Add Mediator pattern description

This commit is contained in:
Petrutiu Mihai
2016-07-12 18:20:19 +03:00
parent 508a23c6f7
commit b3c6a985e2
3 changed files with 82 additions and 1 deletions

View File

@@ -155,15 +155,93 @@ Some use the term container, some use the term aggregate, is one and the same th
4. Mediator pattern
------------------
### a. 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.
### b. When to use Mediator pattern
* A collection of interacting objects whose interaction needs simplification
* When you need to monitor/audit the communication between objects
* When building UI components -> High level components mediate the communication between subcomponents
* When you want to do publish/subscribe -> publish subscribe is a pattern implemented using mediator
### c. 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
### d. Pitfalls
* Mediator can become ver complicated as more colleagues are handled.
### e. Flavors
Don't know
### f. Examples
* StockExchange example: Starting class: StockExchange.StockExchangeExample
* Have multiple traders Buy/Sell actions from stock exchange (simplified)
* Ground-Air traffic control example: Starting class: GroupAirTrafficControl.GroundAirTrafficControlExample
* Have 4 planes that want to land on an airport, the airport has 4 lines (one not working).
They all talk to air traffic control(mediator) to ask permission to land, instead of talking to each other
* Air traffic control example: Starting class: FlightAirTrafficControl.FlightAirTrafficControlExample
* Have multiple planes flying in the same zone, at different attitudes, instead of having them communicating to each other,
they all comunicate to the tower, and the tower tells them if they need to change the altitude
* Many to many relationship in code: No running class, only the models: User-UserToGroup-Group
* Other possible examples that are not yet implemented -> Chat application, GUI Library, Taxi/Taxi Center
5. Memento pattern
------------------
### a. Pattern description
### b. When to use Memento pattern
### c. Actors
### d. Pitfalls
### e. Flavors
### f. Examples
6. Observer pattern
------------------
### a. Pattern description
### b. When to use Observer pattern
### c. Actors
### d. Pitfalls
### e. Flavors
### f. Examples
7. State pattern
------------------
### a. Pattern description
### b. When to use State pattern
### c. Actors
### d. Pitfalls
### e. Flavors
### f. Examples
8. Strategy pattern
------------------
### a. Pattern description
### b. When to use Strategy pattern
### c. Actors
### d. Pitfalls
### e. Flavors
### f. Examples
9. Template pattern
------------------
### a. Pattern description
### b. When to use Template pattern
### c. Actors
### d. Pitfalls
### e. Flavors
### f. Examples
10. Visitor pattern
------------------
### a. Pattern description
### b. When to use Visitor pattern
### c. Actors
### d. Pitfalls
### e. Flavors
### f. Examples

View File

@@ -32,7 +32,7 @@ namespace MediatorPattern
//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 design pattern, but a mediator assumes more
// It's almost pub/sub, pub sub is implemented using mediator design pattern, but a mediator assumes more knowledge of the colleagues
}

View File

@@ -5,6 +5,9 @@ using System.Threading.Tasks;
namespace MediatorPattern.StockExchange
{
/// <summary>
/// Mediator implementation
/// </summary>
public class StockExchange : IStockExchange
{
Dictionary<string, List<Trader>> sellers;