packagecn.imcompany.adapter;/**
* Created by tomyli on 2018/6/22.
* Github: https://github.com/peng051410
*/publicinterfaceThirdLogin{voidwechatLogin(StringaccessToken);voidqqLogin(StringaccessToken);voidsinaLogin(StringaccessToken);}
packagecn.imcompany.adapter;/**
* Created by tomyli on 2018/6/22.
* Github: https://github.com/peng051410
*/publicclassThirdLoginAdapterimplementsThirdLogin{privateLoginServiceloginService;publicThirdLoginAdapter(){this.loginService=newLoginService();}@OverridepublicvoidwechatLogin(StringaccessToken){System.out.println("微信获取用户信息");loginService.login(accessToken,null);}@OverridepublicvoidqqLogin(StringaccessToken){System.out.println("qq获取用户信息");loginService.login(accessToken,null);}@OverridepublicvoidsinaLogin(StringaccessToken){System.out.println("微博获取用户信息");loginService.login(accessToken,null);}}
packagecn.imcompany.adapter.def;/**
* Created by tomyli on 2018/6/22.
* Github: https://github.com/peng051410
*/publicinterfaceIMemberService{voidsaveMember();voidgetMember();booleanisGirl();booleanisBoy();booleanisVip();}
packagecn.imcompany.adapter.def;/**
* Created by tomyli on 2018/6/22.
* Github: https://github.com/peng051410
*/publicabstractclassAbstractMemberServiceimplementsIMemberService{publicabstractvoidsaveMember();publicabstractvoidgetMember();@OverridepublicbooleanisGirl(){returnfalse;}@OverridepublicbooleanisBoy(){returntrue;}@OverridepublicbooleanisVip(){returnfalse;}}
接下来真正类只需要继承这个抽象类来重写一些特定的方法就可以了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
packagecn.imcompany.adapter.def;/**
* Created by tomyli on 2018/6/22.
* Github: https://github.com/peng051410
*/publicclassMemberServiceextendsAbstractMemberService{@OverridepublicvoidsaveMember(){System.out.println("saveMember");}@OverridepublicvoidgetMember(){System.out.println("getMember");}}