File tree Expand file tree Collapse file tree
src/main/java/com/cpucode/pattern/adapter/login/adapter Expand file tree Collapse file tree Original file line number Diff line number Diff line change 9595## [ 适配器模式] ( src/main/java/com/cpucode/pattern/adapter )
9696
9797- [x] [ 电压适配器] ( src/main/java/com/cpucode/pattern/adapter/power/adapter/ObjectAdapterTest.java )
98+ - [x] [ 登录适配器] ( src/main/java/com/cpucode/pattern/adapter/login/adapter/v1/service/SigninForThirdServiceTest.java )
99+
98100
99101## [ 装饰器模式] ( )
100102
Original file line number Diff line number Diff line change 1+ package com .cpucode .pattern .adapter .login .adapter ;
2+
3+ /**
4+ * @author : cpucode
5+ * @date : 2021/6/4
6+ * @time : 21:23
7+ * @github : https://github.com/CPU-Code
8+ * @csdn : https://blog.csdn.net/qq_44226094
9+ */
10+ public class Member {
11+ private String username ;
12+ private String password ;
13+ private String mid ;
14+ private String info ;
15+
16+ public String getUsername () {
17+ return username ;
18+ }
19+
20+ public void setUsername (String username ) {
21+ this .username = username ;
22+ }
23+
24+ public String getPassword () {
25+ return password ;
26+ }
27+
28+ public void setPassword (String password ) {
29+ this .password = password ;
30+ }
31+
32+ public String getMid () {
33+ return mid ;
34+ }
35+
36+ public void setMid (String mid ) {
37+ this .mid = mid ;
38+ }
39+
40+ public String getInfo () {
41+ return info ;
42+ }
43+
44+ public void setInfo (String info ) {
45+ this .info = info ;
46+ }
47+ }
Original file line number Diff line number Diff line change 1+ package com .cpucode .pattern .adapter .login .adapter ;
2+
3+ /**
4+ * 创建统一的返回结果
5+ *
6+ * @author : cpucode
7+ * @date : 2021/6/4
8+ * @time : 21:07
9+ * @github : https://github.com/CPU-Code
10+ * @csdn : https://blog.csdn.net/qq_44226094
11+ */
12+ public class ResultMsg {
13+ private int code ;
14+ private String msg ;
15+ private Object data ;
16+
17+ public ResultMsg () {}
18+
19+ public ResultMsg (int code , String msg , Object data ) {
20+ this .code = code ;
21+ this .msg = msg ;
22+ this .data = data ;
23+ }
24+
25+ public int getCode () {
26+ return code ;
27+ }
28+
29+ public void setCode (int code ) {
30+ this .code = code ;
31+ }
32+
33+ public String getMsg () {
34+ return msg ;
35+ }
36+
37+ public void setMsg (String msg ) {
38+ this .msg = msg ;
39+ }
40+
41+ public Object getData () {
42+ return data ;
43+ }
44+
45+ public void setData (Object data ) {
46+ this .data = data ;
47+ }
48+ }
Original file line number Diff line number Diff line change 1+ package com .cpucode .pattern .adapter .login .adapter .v1 .service ;
2+
3+ import com .cpucode .pattern .adapter .login .adapter .Member ;
4+ import com .cpucode .pattern .adapter .login .adapter .ResultMsg ;
5+
6+ /**
7+ * 老系统的登录逻辑
8+ *
9+ * @author : cpucode
10+ * @date : 2021/6/4
11+ * @time : 21:08
12+ * @github : https://github.com/CPU-Code
13+ * @csdn : https://blog.csdn.net/qq_44226094
14+ */
15+ public class SiginService {
16+ /**
17+ * 注册方法
18+ * @param username
19+ * @param password
20+ * @return
21+ */
22+ public ResultMsg regist (String username , String password ){
23+ return new ResultMsg (200 ,"注册成功" , new Member ());
24+ }
25+
26+ /**
27+ * 登录的方法
28+ * @param username
29+ * @param password
30+ * @return
31+ */
32+ public ResultMsg login (String username ,String password ){
33+ return null ;
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ package com .cpucode .pattern .adapter .login .adapter .v1 .service ;
2+
3+ import com .cpucode .pattern .adapter .login .adapter .ResultMsg ;
4+
5+ /**
6+ * 稳定的方法不去动, 直接继承下来
7+ *
8+ * @author : cpucode
9+ * @date : 2021/6/4
10+ * @time : 21:24
11+ * @github : https://github.com/CPU-Code
12+ * @csdn : https://blog.csdn.net/qq_44226094
13+ */
14+ public class SigninForThirdService extends SiginService {
15+ public ResultMsg loginForQQ (String openId ){
16+ //1、openId是全局唯一,我们可以把它当做是一个用户名(加长)
17+ //2、密码默认为QQ_EMPTY
18+ //3、注册(在原有系统里面创建一个用户)
19+
20+ //4、调用原来的登录方法
21+
22+ return loginForRegist (openId ,null );
23+ }
24+
25+ public ResultMsg loginForWechat (String openId ){
26+ return null ;
27+ }
28+
29+ public ResultMsg loginForToken (String token ){
30+ //通过token拿到用户信息,然后再重新登陆了一次
31+ return null ;
32+ }
33+
34+ public ResultMsg loginForTelphone (String telphone , String code ){
35+
36+ return null ;
37+ }
38+
39+ public ResultMsg loginForRegist (String username , String password ){
40+ super .regist (username ,null );
41+ return super .login (username ,null );
42+ }
43+
44+ }
Original file line number Diff line number Diff line change 1+ package com .cpucode .pattern .adapter .login .adapter .v1 .service ;
2+
3+ /**
4+ * @author : cpucode
5+ * @date : 2021/6/4
6+ * @time : 21:28
7+ * @github : https://github.com/CPU-Code
8+ * @csdn : https://blog.csdn.net/qq_44226094
9+ */
10+ public class SigninForThirdServiceTest {
11+ public static void main (String [] args ) {
12+ SigninForThirdService service = new SigninForThirdService ();
13+
14+ //不改变原来的代码, 也要能够兼容新的需求
15+ // 还可以再加一层策略模式
16+ service .login ("tom" ,"123456" );
17+ service .loginForQQ ("sdfasdfasf" );
18+ service .loginForWechat ("sdfasfsa" );
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments