Пример #1
0
        static void Main(string[] args)
        {
            IDataLayer <CustomerBase> dalcust = FactoryDal <CustomerBase> .getDal("EfCustDal");

            IDataLayer <AddressBase> daladd = FactoryDal <AddressBase> .getDal("EfAddDal");

            IDataLayer <PhoneBase> dalphone = FactoryDal <PhoneBase> .getDal("EfPhoneDal");

            Mediator.Mediator obj = new Mediator.Mediator(dalcust, daladd, dalphone);
            CustomerBase      c   = Factory <CustomerBase> .Create("Customer");

            c.CustomerName = "tesy123";
            c.PhoneNumber  = "90909";
            c.BillDate     = Convert.ToDateTime("1/1/2010");
            c.Type         = "Customer";
            c.BillAmount   = 100;
            obj.Add(c);
            AddressBase a = Factory <AddressBase> .Create("Address");

            a.Address1 = "Mulund";
            obj.Add(a);
            PhoneBase p = Factory <PhoneBase> .Create("Phone");

            p.PhoneNumber = "222";
            obj.Add(p, 0);
            obj.SaveAll();
        }
Пример #2
0
        public void UnRegisterObjectTest()
        {
            Mediator.Mediator target = Mediator.Mediator.Instance;
            MockObject        m      = new MockObject();

            Assert.AreEqual(true, target.IsRegistered(m));
            target.UnRegisterObject(m);
            Assert.AreEqual(false, target.IsRegistered(m));
            Debug.WriteLine((char)1060);
        }
Пример #3
0
        public void UnRegisterTest1()
        {
            Mediator.Mediator target = Mediator.Mediator.Instance;
            MockObject        m      = new MockObject();

            Assert.AreEqual(true, target.IsRegistered(m));
            target.NotifyColleagues(1, 5);
            Assert.AreEqual(5, m.Index);
            target.UnRegister(m._Action);

            target.NotifyColleagues(1, 10);
            Assert.AreEqual(5, m.Index);
        }
 /**
  *
  */
 public ConcreteColleague2(Mediator mediator)
     : base(mediator)
 {
 }
Пример #5
0
 public MockObject()
 {
     Mediator.Mediator target = Mediator.Mediator.Instance;
     _Action = test;
     target.Register(1, _Action);
 }
Пример #6
0
        public static void Main()
        {
            //Builder
            var builder = new CodeBuilder("Person").AddField("string", "Name").AddField("int", "Age");

            Console.WriteLine(builder.ToString());

            //Factory
            var factory = new F.Factory();
            var person  = factory.CreateInstance("Alexander");

            // Numbers of models should be as pointers to the Factories if we want to have different models instatiated from one Factory
            Console.WriteLine(person);

            //Prototype
            Point one = new Point {
                X = 1, Y = 2
            };
            Point two = new Point {
                X = 3, Y = 4
            };
            Line line = new Line {
                Start = one, End = two
            };
            Line copiedLine = line.DeepCopyJson();

            copiedLine.Start.X = 57;

            Console.WriteLine(line);
            Console.WriteLine(copiedLine);

            //Flyweight
            var sentence = new Sentence("Hasta la vista");

            sentence[0].IsCapitalized = true;
            Console.WriteLine(sentence);

            //Proxy
            var person1 = new PersonProxy(new Person {
                Age = 21
            });

            Console.WriteLine(person1.Drive());
            person1.Age = 14;
            Console.WriteLine(person1.Drink());

            //Bridge
            var circle = new Circle();
            var square = new Square();

            Console.WriteLine(circle.ToString());
            Console.WriteLine(square.ToString());

            //Composite
            var manyValues = new ManyValues
            {
                new SingleValue {
                    Value = 5
                },
                new SingleValue {
                    Value = 3
                },
                new SingleValue {
                    Value = 2
                }
            };
            var some = manyValues.Sum();

            //ChainOfResponsibility
            var game       = new Game();
            var goblin     = new Goblin(game);
            var goblinKing = new GoblinKing(game);

            //Mediator
            Use.Mediator mediator = new Use.Mediator();
            var          p1       = new Participant(mediator);
            var          p2       = new Participant(mediator);

            p1.Say(2);
            p2.Say(4);

            //Memento
            var ba = new BankAccount(100);
            var m1 = ba.Deposit(50); // 150
            var m2 = ba.Deposit(25); // 175

            Console.WriteLine(ba);
            // restore to m1
            ba.Restore(m1);
            Console.WriteLine(ba);
            ba.Restore(m2);
            Console.WriteLine(ba);
        }
Пример #7
0
 // Constructor
 public Colleague(Mediator mediator)
 {
     this.mediator = mediator;
 }
 public ConcreteColleague2(Mediator mediator) : base(mediator)
 {
 }
Пример #9
0
 public Person(Mediator mediator)
 {
     this.mediator = mediator;
 }
Пример #10
0
 public void SendMessage(string msg)
 {
     Mediator.SendMessage(msg, this);
 }
Пример #11
0
 public void Send(string message) => Mediator.Send(message, this);
 public void setMediator(Mediator mediator)
 {
     this.mediator = mediator;
 }