可以运行一下试试~你就会明白

using System;
using System.Collections.Generic;
using System.Text;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            FlowB flowB = new FlowB();
            flowB.Run(); //复用了Flow的流程并采用了自己的B步骤
            Console.ReadLine();
        }
    }
    public class Flow
    {
        public void A()
        {
            Console.WriteLine("F A");
        }

        public virtual void B()
        {
            Console.WriteLine("F B");
        }

        public void C()
        {
            Console.WriteLine("F C");
        }

        public void Run()
        {
            A();
            B(); //步骤B是扩展点 ,可以由子类决定具体执行什么
            C();
        }
    }

    public class FlowA : Flow
    {
        public override void B()
        {
            //执行FlowA的B步骤
        }
    }

    public class FlowB : Flow
    {
        public override void B()
        {
            Console.WriteLine("FBB");
        }
    }

}

相关文章:

  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-12
  • 2022-12-23
  • 2021-10-07
  • 2021-09-10
相关资源
相似解决方案