首页 > 代码库 > 11 攻击特效与击中反应-模板方法模式(Template Method)

11 攻击特效与击中反应-模板方法模式(Template Method)

技术分享

 

技术分享
 1 /// <summary>
 2 /// 定义完整算法的各个步骤及执行顺序
 3 /// </summary>
 4 public abstract class AbstractClass {
 5     public void TemplateMethod() {
 6         PrimitiveOperation1();
 7         PrimitiveOperation2();
 8     }
 9 
10     protected abstract void PrimitiveOperation1();
11     protected abstract void PrimitiveOperation2();
12 }
AbstractClass
技术分享
 1 /// <summary>
 2 /// 具体实现A
 3 /// </summary>
 4 public class ConcreteClassA:AbstractClass {
 5 
 6     protected override void PrimitiveOperation1() {
 7         Debug.Log("ConcreteClassA.PrimitiveOperation1");
 8     }
 9 
10     protected override void PrimitiveOperation2() {
11         Debug.Log("ConcreteClassA.PrimitiveOperation2");
12     }
13 }
ConcreteClassA
技术分享
 1 /// <summary>
 2 /// 具体实现B
 3 /// </summary>
 4 public class ConcreteClassB:AbstractClass {
 5     protected override void PrimitiveOperation1() {
 6         Debug.Log("ConcreteClassB.PrimitiveOperation1");
 7     }
 8 
 9     protected override void PrimitiveOperation2() {
10         Debug.Log("ConcreteClassB.PrimitiveOperation2");
11     }
12 }
ConcreteClassB

 

11 攻击特效与击中反应-模板方法模式(Template Method)