Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        ConcreteSubject subject  = new ConcreteSubject();
        Observer        observer = new ConcreteObserver();

        subject.AddObserver(observer);
        subject.State = "下雨";
        subject.State = "下雪";
    }
        public static void Main(string[] args)
        {
            ConcreteSubject s = new ConcreteSubject();

            s.AddObserver(new ConcreteObserver()
            {
                Name = "A"
            });
            s.AddObserver(new ConcreteObserver()
            {
                Name = "B"
            });
            s.AddObserver(new ConcreteObserver()
            {
                Name = "C"
            });

            s.SubjectState = "Where have all the flowers gone ?";

            Console.ReadLine();
        }
Ejemplo n.º 3
0
 public ConcreteObserver(ConcreteSubject subject)
 {
     _subject = subject;
     _subject.AddObserver(this);
 }