Template Method模式的几个角色:基类角色:定义的抽象方法、纯虚方法(一般设置为protected),Template方法(是对抽象方法、纯虚方法包装). 子类角色:重写基类的抽象方法、纯虚方法.客户端角色:调用子类中的重写过的方法.演示代码如下: using System;using System.Collections.Generic;using System.Text;using System.Collections;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