観察者モード(猫が大声で叫ぶと、主人が目を覚まし、ネズミが走る)


    public delegate void SubEventHandle();

    public abstract class Subject

    {

       

        public event SubEventHandle SubEvent;

        public void OnSub() 

        {

            if (SubEvent != null)

                SubEvent();

        }

    }



    public abstract class Observer 

    {

        public Observer(Subject sub) 

        {

            sub.SubEvent += new SubEventHandle(Response);

        }

        protected abstract void Response();

    }



    public class Mouse : Observer 

    {

        public Mouse(Subject sub):base(sub)

        {

            

        }

        public override void Response()

        {

            

        }

    }



    public class Master : Observer 

    {

        public Master(Subject sub) : base(sub) 

        {

        }



        protected override void Response()

        {

            

        }

    }



    public class Cat : Subject

    {

        private List<Observer> observers;

        public Cat()

        {

            observers = new List<Observer>();

        }



        public void Cry()

        {

            base.OnSub();

        }

    }