示例#1
0
    void TestObserver()
    {
        Secretary newSecretary = new Secretary();

        StockObserver stockGuy = new StockObserver("Stock Guy", newSecretary);
        NBAObserver   nbaGuy   = new NBAObserver("NBA Guy", newSecretary);

        newSecretary.Attach(stockGuy);
        newSecretary.Attach(nbaGuy);

        newSecretary.DeTach(stockGuy);

        newSecretary.Nofity();
    }
示例#2
0
        static void Main(string[] args)
        {
            Secretary Marry = new Secretary();

            stockObserver Marry1 = new stockObserver("瑪莉", Marry);
            stockObserver Marry2 = new stockObserver("強尼", Marry);

            Marry.Attach(Marry1);
            Marry.Attach(Marry2);

            Marry.SecretaryAction = "老闆回來了";

            Marry.Notify();

            Console.Read();
        }