Template Method模式的几个角色:

基类角色:定义的抽象方法、纯虚方法(一般设置为protected),Template方法(是对抽象方法、纯虚方法包装).
子类角色:重写基类抽象方法、纯虚方法.
客户端角色:调用子类中的重写过的方法.

演示代码如下:

TemplateMethod模式using System;
TemplateMethod模式
using System.Collections.Generic;
TemplateMethod模式
using System.Text;
TemplateMethod模式
using System.Collections;
TemplateMethod模式
namespace TemplateMethod


Template Method模式的实质就是在基类定义一个Template 再在子类中重写Template中的具体方法,以便客户端访问.

相关文章:

  • 2021-06-06
  • 2021-10-06
  • 2022-12-23
  • 2021-09-07
  • 2021-12-07
  • 2021-07-26
  • 2022-03-07
猜你喜欢
  • 2021-05-10
  • 2021-05-27
  • 2021-06-18
  • 2021-06-09
  • 2021-09-16
相关资源
相似解决方案