Files
behavioral-patterns/src/MediatorPattern/MediatorPatternExamples.cs
2016-07-14 15:03:45 +03:00

81 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using MediatorPattern.FlightAirTrafficControl;
using MediatorPattern.GroundAirTrafficControl;
using MediatorPattern.StockExchange;
using System;
namespace MediatorPattern
{
public class MediatorPatternExamples
{
public static void Run()
{
Console.WriteLine(GetPatternDescription());
Console.WriteLine(GetActors());
Console.WriteLine(WhenToUseIt());
Console.WriteLine(GetDisadvances());
GoToNextStep();
StockExchangeExample stockExample = new StockExchangeExample();
stockExample.Run();
GoToNextStep();
GroundAirTrafficControlExample groundAirControl = new GroundAirTrafficControlExample();
groundAirControl.Run();
GoToNextStep();
FlightAirTrafficControlExample flightAirControl = new FlightAirTrafficControlExample();
flightAirControl.Run();
GoToNextStep();
//Taxi/Taxi center example
//Chat application
//GUI libraries
//https://www.javacodegeeks.com/2015/09/mediator-design-pattern.html
//Dispatcher from facebook -> flux -> https://youtu.be/nYkdrAPrdcw?list=PLb0IAmt7-GS188xDYE-u1ShQmFFGbrk0v&t=735
// It's almost pub/sub, pub sub is implemented using mediator design pattern, but a mediator assumes more knowledge of the colleagues
}
static string GetPatternDescription()
{
return @"Pattern description:
With the mediator pattern, communication between objects is encapsulated with a mediator object.
Objects no longer communicate directly with each other, but instead communicate through the mediator.
This reduces the dependencies between communicating objects, thereby lowering the coupling.";
}
static string GetActors()
{
return @"Actors:
Mediator: interface of the mediator, that defines what messages does it mediate between colleagues.
Concrete Mediator: implementation of the interface
Colleague: objects that communicate through the mediator
";
}
static string WhenToUseIt()
{
return @"When to use it:
Identify a collection of interacting objects whose interaction needs simplification
Get a new abstract class that encapsulates that interaction
Create a instance of that class and redo the interaction with that class alone
But, dont play God!
";
}
static string GetDisadvances()
{
return @"Disatvantages:
Mediator can become ver complicated as more colleagues are handled";
}
private static void GoToNextStep()
{
Console.ReadKey();
Console.Clear();
}
}
}