packagecn.imcompany.delegate;/**
* Created by tomyli on 2018/6/27.
* Github: https://github.com/peng051410
*/publicinterfaceMember{voidshowName();voidshowSkill();voiddoWork();}
packagecn.imcompany.delegate;/**
* Created by tomyli on 2018/6/27.
* Github: https://github.com/peng051410
*/publicclassBossimplementsMember{@OverridepublicvoidshowName(){System.out.println("i am boss");}@OverridepublicvoidshowSkill(){System.out.println("send commend");}@OverridepublicvoiddoWork(){}}
packagecn.imcompany.delegate;/**
* Created by tomyli on 2018/6/27.
* Github: https://github.com/peng051410
*/publicclassLeaderimplementsMember{privateMemberdeveloperA;privateMemberdeveloperB;publicvoidsetDeveloperA(MemberdeveloperA){this.developerA=developerA;}publicvoidsetDeveloperB(MemberdeveloperB){this.developerB=developerB;}@OverridepublicvoidshowName(){System.out.println("i am leader");}@OverridepublicvoidshowSkill(){showName();System.out.println("i want to select member to doWork");}publicvoiddoWork(){showSkill();developerA.doWork();developerB.doWork();}}publicclassDeveloperAimplementsMember{@OverridepublicvoidshowName(){System.out.println("i am developer a");}@OverridepublicvoidshowSkill(){showName();System.out.println("i can do login function");}publicvoiddoWork(){showSkill();System.out.println("start work login");}}publicclassDeveloperBimplementsMember{@OverridepublicvoidshowName(){System.out.println("i am developer b");}@OverridepublicvoidshowSkill(){showName();System.out.println("i can do pay function");}publicvoiddoWork(){showSkill();System.out.println("start do pay");}}
packagecn.imcompany.delegate;/**
* Created by tomyli on 2018/6/27.
* Github: https://github.com/peng051410
*/publicclassWorkTest{publicstaticvoidmain(String[]args){Bossboss=newBoss();boss.showName();boss.showSkill();Leaderleader=newLeader();MembermemberA=newDeveloperA();MembermemberB=newDeveloperB();leader.setDeveloperA(memberA);leader.setDeveloperB(memberB);leader.doWork();}}