Пример #1
0
 public void AddInvestor(Investors Investor)
 {
     if (Investor != null)
     {
         _listOfInvestors.Add(Investor);
     }
 }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Behavioural Patterns Implemenation");
            Console.WriteLine("Chain of Responsibility");
            Manager manager = new Manager();
            VP      vp      = new VP();
            AVP     avp     = new AVP();

            avp.SetManager(vp);
            manager.SetManager(avp);
            manager.ApproveSum(1000);
            manager.ApproveSum(11000);
            manager.ApproveSum(20000);
            manager.ApproveSum(10000434);
            Console.WriteLine("Command Pattern");
            Client client = new Client();

            client.Compute('+', 3);
            client.Compute('-', 5);
            client.Compute('/', 4);
            client.Compute('*', 1);
            client.Undo(4);
            client.Redo(3);
            Console.WriteLine("Current value " + client.currentValue());
            Console.WriteLine("IteratorPattern");
            Collection cl = new Collection();

            cl[0] = "a";
            cl[1] = "b";
            cl[2] = "c";
            Iterator it = new Iterator(cl);

            Console.WriteLine("Next " + it.Next().Name);
            Console.WriteLine("Current " + it.CurrentItem().Name);
            Console.WriteLine("First " + it.First().Name);
            it.Step = 2;
            Console.WriteLine("Next with Step 2 " + it.Next().Name);
            Console.WriteLine("Interface pattern");
            ChatRoom            chatRoom     = new ChatRoom();
            AbstractParticipant participant1 = new Participant("John");
            AbstractParticipant participant2 = new Participant("Sam");
            AbstractParticipant participant3 = new Participant("Mark");

            participant1.AddChatRoom(chatRoom);
            participant2.AddChatRoom(chatRoom);
            participant3.AddChatRoom(chatRoom);
            chatRoom.Register("John", participant1);
            chatRoom.Register("Mark", participant3);
            chatRoom.Register("Sam", participant2);
            participant1.Send("Sam", "hello Sam");
            participant1.Send("Mark", "hello Mark");
            participant2.Send("John", "hello John");
            participant2.Send("Mark", "hello Mark");
            participant3.Send("Sam", "hello Sam");
            participant3.Send("John", "hello John");
            Console.WriteLine("Memento Pattern");
            Orginator o = new Orginator();

            o.Name   = "Jack willis";
            o.Budget = 10000;
            o.Phone  = "(1)343234323";
            o.DisplayStuff();
            ProspectiveMemory p = new ProspectiveMemory();

            p.memento = o.SaveMomento();
            o.Name    = "John willis";
            o.Budget  = 100200;
            o.Phone   = "(1)343233323";
            o.DisplayStuff();
            o.RestoreMemento(p.memento);
            o.DisplayStuff();
            Console.WriteLine("Observer Pattern");
            Stock     Ibm   = new IBM("IBM", 500);
            Investors John  = new Investors("John Willis");
            Investors Jack  = new Investors("Jack Connor");
            Investors James = new Investors("James Deen");

            Ibm.AddInvestor(John);
            Ibm.AddInvestor(James);
            Ibm.AddInvestor(Jack);
            Ibm.Price = 400;
            Ibm.Price = 600;
            Console.WriteLine("State Pattern");
            Account account = new Account("testman");

            account.Deposit(10000);
            account.Deposit(100000);
            account.Withdraw(100000);
            account.Withdraw(20000);
            account.Deposit(1000);
            SortedList strategy = new SortedList();

            strategy.Add("Ramu");
            strategy.Add("Govind");
            strategy.Add("Ramesh");
            strategy.Add("Raghu");
            strategy.Add("Abhijith");
            strategy.SetSortStrategy(new ShellSort());
            strategy.Sort();
            strategy.SetSortStrategy(new MergeSort());
            strategy.Sort();
            strategy.SetSortStrategy(new QuickSort());
            strategy.Sort();
            AbstractShape square = new Square(10);

            square.Calculate();
            AbstractShape circle = new Circle(10);

            circle.Calculate();
            Employees emp = new Employees();

            emp.Add(new Clerk("cindy", 10000, 20));
            emp.Add(new President("Jack", 12200, 24));
            emp.Add(new Director("john", 112200, 25));
            emp.ShowEmployees();
            emp.Accept(new VacationVisitor());
            emp.Accept(new PayVisitor());
            emp.ShowEmployees();
        }