상속: Colleague
예제 #1
0
        void OnEnable()
        {
            Debug.Log("------------------");
            Debug.Log("MEDIATOR DESIGN PATTERN");

            StockMediator nyse = new StockMediator();

            // important here is:
            // in this example they both might be doing nothing different, but
            // they could be totally different objects and calculate stuff different or so
            // but still be able to talk to the mediator the same easy way
            // that's why we have different objects here:
            GormanSlacks broker  = new GormanSlacks(nyse);
            JTPoorman    broker2 = new JTPoorman(nyse);

            nyse.AddColleague(broker);
            nyse.AddColleague(broker2);

            // because they call methods on the same mediator object they talk to the same mediator
            // who handles all the stock exanche and keeps track of that. so the brokers by themselves
            // don't know anything about each other. which is a good thing :-)
            broker.SaleOffer(Stock.MSFT, 100);
            broker.SaleOffer(Stock.GOOG, 50);

            broker2.BuyOffer(Stock.MSFT, 100);
            broker2.SaleOffer(Stock.NRG, 10);

            broker.BuyOffer(Stock.NRG, 10);
            broker.BuyOffer(Stock.NRG, 50);

            nyse.PrintStockOfferings();
        }
예제 #2
0
        static void Main(string[] args)
        {
            StockMediator nyse = new StockMediator();

            GormanSlacks broker = new GormanSlacks(nyse);

            JTPoorman broker2 = new JTPoorman(nyse);

            broker.SaleOffer("MSFT", 100);
            broker.SaleOffer("GOOG", 50);

            broker2.BuyOffer("MSFT", 100);
            broker2.SaleOffer("NRG", 10);

            broker.BuyOffer("NRG", 10);

            nyse.GetStockOfferings();

            Console.ReadKey();
        }
        void OnEnable()
        {
            Debug.Log ("------------------");
            Debug.Log ("MEDIATOR DESIGN PATTERN");

            StockMediator nyse = new StockMediator();

            // important here is:
            // in this example they both might be doing nothing different, but
            // they could be totally different objects and calculate stuff different or so
            // but still be able to talk to the mediator the same easy way
            // that's why we have different objects here:
            GormanSlacks broker = new GormanSlacks(nyse);
            JTPoorman broker2 = new JTPoorman(nyse);

            nyse.AddColleague(broker);
            nyse.AddColleague(broker2);

            // because they call methods on the same mediator object they talk to the same mediator
            // who handles all the stock exanche and keeps track of that. so the brokers by themselves
            // don't know anything about each other. which is a good thing :-)
            broker.SaleOffer(Stock.MSFT, 100);
            broker.SaleOffer(Stock.GOOG, 50);

            broker2.BuyOffer(Stock.MSFT, 100);
            broker2.SaleOffer(Stock.NRG, 10);

            broker.BuyOffer(Stock.NRG, 10);
            broker.BuyOffer(Stock.NRG, 50);

            nyse.PrintStockOfferings();
        }