Mediator pattern, used to handle complex communications between related objects, helping with decoupling of those objects.
Example :-
An airport control tower is an excellent example of the mediator pattern. The tower looks after who can take off and land - all communications are done from the airplane to control tower, rather than having plane-to-plane communication. This idea of a central controller is one of the key aspects to the mediator pattern.
private class AirPlane:ControllRoom
{
private String m_sAirPlaneNumber =null;
public AirPlane(String sAirPlaneNumber)
{
m_sAirPlaneNumber = sAirPlaneNumber;
}
public Register(Airplane objAirplane)
{
m_arlsAirplanes.Add(objAirplane);
}
}
private class ControllRoom
{
private Arraylist m_arlsAirplanes =null;
public Arraylist Airplanes
{
get
{
return m_arlsAirplanes;
}
}
public ControllRoom()
{
m_arlstAirplanes = new Arraylist();
}
private Arraylist m_arlstOnAirport =null;
public Arraylist OnAirport
{
get
{
return m_arlstOnAirPort;
}
}
public void AddOnAirPort(Airplane objAirplane)
{
m_arlstOnAirPort.Add(objAirplane);
}
public void RemoveFromAirPort(Airplane objAirplane)
{
m_arlstOnAirPort.Remove(objAirplane);
}
}
static void main()
{
Airplane objAirplaneA = new Airplane(“A100”);
objAirplaneA.Register(objAirplane);
if(objAirplaneA.OnAirport.Count <= 1)
objAirPlaneA.AddOnAirport(objAirplaneA);
Airplane objAirplaneB = new Airplane(“B100”);
objAirplaneB.Register(objAirplaneB);
if(objAirplaneB.OnAirport.Count <= 1)
objAirPlaneB.AddOnAirport(objAirplaneB);
}
}
Saturday, November 13, 2010
Subscribe to:
Post Comments (Atom)
Followers
Link
Labels
Agille
(3)
Angular 2
(96)
Architecture
(7)
ASP .Net
(30)
C#/VB .Net
(161)
Entityframework
(11)
General
(33)
Git
(2)
Hosting
(2)
HTML
(4)
Interview
(12)
Interview-Agile
(1)
Interview-Angular
(25)
Interview-ASP .Net
(3)
Interview-C#
(16)
Interview-JavaScript
(1)
Interview-MVC
(30)
Interview-SQL Server
(4)
Interview-WCF
(2)
Islam
(6)
Java Script
(37)
JQuery
(1)
MVC
(53)
NodeJS
(1)
Puzzles
(1)
React-Native
(3)
Security
(1)
Shayri
(10)
SQL Server
(41)
VC++
(5)
WCF
(21)
Web API
(27)
WPF
(21)
No comments:
Post a Comment