您的位置:首页 > 其它

设计模式--模板方法模式(照旧,有类关系图)

2008-08-04 19:49 573 查看


 

 

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

namespace ConsoleApplication1
{
    public class TheFather
    {
        public void BaseMethod1()
        {
            Console.WriteLine("吃了吗?");
            BaseMethod2();
        }

        public virtual void BaseMethod2()
        {

        }
    }

    public class Son1 : TheFather
    {
        public override void BaseMethod2()
        {
            Console.WriteLine("吃了");
        }
    }

    public class Son2 : TheFather
    {
        public override void BaseMethod2()
        {
            Console.WriteLine("还没呢");
        }
    }

    public class Client
    {
        public static void Main()
        {
            TheFather obj = new Son1();
            obj.BaseMethod1();

            obj = new Son2();
            obj.BaseMethod1();

            Console.Read();
        }
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  设计模式 class