Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Mediator
- {
- public void Run()
- {
- Brain humman = new Brain();
- }
- }
- class Brain
- {
- public Brain()
- {
- CreateBodyPrts();
- }
- public static void CreateBodyPrts()
- {
- Ear = new Ear(this);
- Hand = new Hand(this);
- Eye = new Eye(this);
- }
- public Ear Ear{get; private set;}
- public Hand Hand{get; private set;}
- public Eye Eye{get; private set;}
- public void SomethingHappendToBodyParts(BodyPart bodyPart)
- {
- if(bodyPart is Ear)
- {
- string hearSounds = ((Ear)bodyPart).getSounds();
- if(hearSounds.Contains("hallo"))
- {
- Hand.WaveHand();
- }
- }
- if(bodyPart is Eye)
- {
- string seeSomething = ((Eye)bodyPart).HearSomething();
- }
- }
- }
- class BodyPart
- {
- private readonly Brain _brain;
- BodyPart(Brain brain)
- {
- _brain = brain;
- }
- public void Changed()
- {
- _brain.SomethingHappendToBodyParts(this);
- }
- }
- class Hand :BodyPart
- {
- public Hand(Brain brain) : base(brain){}
- public void WaveHand()
- {
- Console.Writeline("My hand is waving.");
- }
- }
- class Ear : BodyPart
- {
- private string _sounds = string.Empty;
- Ear(Brain brain) : base(brain){}
- public string getSounds()
- {
- return _sounds;
- }
- public void HearSomething()
- {
- Console.Writeline("Що ти чуєш?");
- _sounds = Console.ReadLine();
- Changed();
- }
- }
- class Eye : BodyPart
- {
- private string whatISee = string.Empty;
- public void SeeSomething()
- {
- Console.Writeline("Що ти бачиш?");
- whatISee = Console.ReadLine();
- Changed();
- }
- public string GetWhatISee()
- {
- return whatISee;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement