现在的位置: 首页 > 综合 > 正文

设计模式–代理模式的简单实现(C#)+类关系图

2013年09月15日 ⁄ 综合 ⁄ 共 710字 ⁄ 字号 评论关闭

关系图

 

 

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

namespace ConsoleApplication1
{
    class Class1
    {
        public static void Main()
        {
            Proxy p = new Proxy();
            p.DoYourStuff();
            Console.Read();
        }
    }

    abstract class ProxyBase
    {
        public abstract  void DoYourStuff();
    }

    class Subject : ProxyBase
    {
        public override void DoYourStuff()
        {
            Console.WriteLine("do my job");
        }
    }

    class Proxy : ProxyBase
    {
        Subject s;
        public override void DoYourStuff()
        {
            if (s == null)
            {
                s = new Subject();
            }
            s.DoYourStuff();
            //throw new NotImplementedException();
        }
    }
}

抱歉!评论已关闭.