Skip to content

Commit

Permalink
add code
Browse files Browse the repository at this point in the history
  • Loading branch information
VentureQ committed Jul 9, 2021
1 parent c2bd2cd commit 5949093
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions code/Design_Pattern/代理模式/Company.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Design_Pattern.代理模式;

public interface Company {
void findWorker(String title);
}
8 changes: 8 additions & 0 deletions code/Design_Pattern/代理模式/HR.java
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);
}
}
27 changes: 27 additions & 0 deletions code/Design_Pattern/代理模式/Proxy.java
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);
}
}
8 changes: 8 additions & 0 deletions code/Design_Pattern/代理模式/Test.java
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");
}
}

0 comments on commit 5949093

Please sign in to comment.