Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Multiton m0 = Multiton.GetInstance(MultitonType.ServiceFoo);
            Multiton m1 = Multiton.GetInstance(MultitonType.ServiceBar);

            Console.WriteLine(m0.ToString());
            Console.WriteLine(m1.ToString());

            Multiton m2 = Multiton.GetInstance(MultitonType.ServiceFoo);
            Multiton m3 = Multiton.GetInstance(MultitonType.ServiceBar);

            Console.WriteLine(m2.ToString());
            Console.WriteLine(m3.ToString());

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public void Start()
        {
            // Constructor is private -- cannot use new
            // We can use singleton objects as parameter
            TaxiMessage(Multiton.Instance(1));

            BusMessage(Multiton.Instance(2));

            TrainMessage(Multiton.Instance(2));

            var m1 = Multiton.Instance(1);
            var m2 = Multiton.Instance(2);

            Console.WriteLine($"Multition {m1.Id} has {m1.NumberOfMessages} message");
            Console.WriteLine($"Multition {m2.Id} has {m2.NumberOfMessages} messages");
        }
Ejemplo n.º 3
0
 private void TrainMessage(Multiton selectedDispatcher)
 {
     selectedDispatcher.SendMessage("Train is waiting for connection");
 }
Ejemplo n.º 4
0
 private void BusMessage(Multiton selectedDispatcher)
 {
     selectedDispatcher.SendMessage("Bus is in a traffic jam");
 }
Ejemplo n.º 5
0
 private void TaxiMessage(Multiton selectedDispatcher)
 {
     selectedDispatcher.SendMessage("Taxi has been arrived to destination");
 }