Example #1
0
        static void Main(string[] args)
        {
            Subject subject = new BadMan();

            Observer police  = new PoliceMan(subject as BadMan);
            Observer citizen = new Citizen(subject as BadMan);
            Observer wife    = new Wife(subject as BadMan);

            BadMan badman = subject as BadMan;

            badman.RunAway("广西");
            Console.WriteLine();
            badman.RunAway("海南");
            Console.WriteLine();
            subject.Detach(wife);
            badman.RunAway("美国");

            subject.Detach(police);
            Console.WriteLine();
            badman.RunAway("澳大利亚");
            Console.WriteLine();
            subject.Detach(citizen);
            badman.RunAway("月球");
        }
Example #2
0
 public Citizen(BadMan target)
 {
     this._target = target;
     this._target.Attach(this);
 }
Example #3
0
 public PoliceMan(BadMan target)
 {
     this._target = target;
     this._target.Attach(this);
 }
Example #4
0
 public Wife(BadMan target)
 {
     this._target = target;
     this._target.Attach(this);
 }