-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package Design_Pattern.代理模式; | ||
|
||
public interface Company { | ||
void findWorker(String title); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package Design_Pattern.代理模式; | ||
|
||
public class HR implements Company{ | ||
@Override | ||
public void findWorker(String title) { | ||
System.out.println("I need worker,title is:"+title); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package Design_Pattern.代理模式; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Proxy implements Company { | ||
private HR hr; | ||
|
||
public Proxy() { | ||
super(); | ||
this.hr = new HR(); | ||
} | ||
|
||
@Override | ||
public void findWorker(String title) {//{需要代理的方法} | ||
hr.findWorker(title); | ||
String worker = getWorker(title); | ||
System.out.println("找到的Worker是:"+worker); | ||
} | ||
|
||
private String getWorker(String title) { | ||
Map<String, String> workList = new HashMap<String, String>(){ | ||
{put("Java", "张三");put("C++", "李四");} | ||
}; | ||
return workList.get(title); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package Design_Pattern.代理模式; | ||
|
||
public class Test { | ||
public static void main(String[] args) { | ||
Company company=new Proxy(); | ||
company.findWorker("Java"); | ||
} | ||
} |