标签:name protected rri stat xtend ali users auth login
模板模式:
package com.dayuanit.service; public abstract class UserService { public void login(String userName, String pwd){ System.out.println("login begin"); first(); second(); third(); System.out.println("login over"); } public void first(){ System.out.println("login 1"); } protected abstract void second(); public void third(){ System.out.println("login 3"); } }
package com.dayuanit.authen; import com.dayuanit.service.UserService; public class AlipayAuthen extends UserService{ @Override protected void second(){ System.out.println("alipay login 2"); } }
package com.dayuanit.authen; import com.dayuanit.service.UserService; public class WeiXinAuthen extends UserService{ @Override public void second(){ System.out.println("weixin login 2"); } }
package com.dayuanit; import com.dayuanit.authen.AlipayAuthen; import com.dayuanit.authen.WeiXinAuthen; public class Test { public static void main(String[] args) { //new UserService().login("tom", "111"); new WeiXinAuthen().login("tom","111"); System.out.println("--------------------------------"); new AlipayAuthen().login("tom", "111"); } }
模板模式结束;
标签:name protected rri stat xtend ali users auth login
原文地址:https://www.cnblogs.com/m-yb/p/8837066.html