码迷,mamicode.com
首页 > 编程语言 > 详细

扯淡设计模式2:java,模板模式,

时间:2018-04-15 11:57:28      阅读:195      评论:0      收藏:0      [点我收藏+]

标签: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");
    }
}

模板模式结束;

 

扯淡设计模式2:java,模板模式,

标签:name   protected   rri   stat   xtend   ali   users   auth   login   

原文地址:https://www.cnblogs.com/m-yb/p/8837066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!