zoukankan      html  css  js  c++  java
  • 学习笔记——模板方法模式

    模拟类:

     1 /**
     2  * 模板方法模式: 实现一个算法时,整体步骤很固定,只有某些部分
     3  * 易变,这是将这些易变部分抽象出来,而先固定好方法执行步骤
     4  * 再让子类实现易变的抽象方法
     5  */
     6 
     7 //模拟到银行办业务
     8 public abstract class BankTransaction {
     9     protected void takeNumber(){
    10         System.out.println("取号");
    11     }
    12 
    13     protected abstract void transact();
    14 
    15     protected void grade(){
    16         System.out.println("完结评分");
    17     }
    18 
    19     //流程在此方法中进行安排
    20     public void process(){
    21         this.takeNumber();
    22         this.transact();
    23         this.grade();
    24     }
    25 }
    26 
    27 class Deposit extends BankTransaction{
    28     @Override
    29     public void transact() {
    30         System.out.println("存款1E");
    31     }
    32 }
    33 
    34 class Withdraw extends BankTransaction{
    35     @Override
    36     public void transact() {
    37         System.out.println("取款");
    38     }
    39 }
    View Code

    测试类:

    1 public class Test {
    2     public static void main(String[] args){
    3         BankTransaction b = new Withdraw();
    4         b.process();
    5     }
    6 }
    View Code
  • 相关阅读:
    博客园页面设置(转载)
    正则表达式30分钟入门教程 (转载)
    如何写出优雅的代码
    centos7 nginx+php5.6+mysql安装与配置
    git 进阶
    js 异步解决方案
    行动派
    unicode 与 utf-8
    bower command not found--windows
    click事件细节
  • 原文地址:https://www.cnblogs.com/Hr666/p/10384649.html
Copyright © 2011-2022 走看看