|
The mediator pattern is a software design pattern that provides a unified interface to a set of interfaces in a subsystem. In software engineering, design patterns are standard solutions to common problems in software design. ...
An interface defines the communication boundary between separate computer components. ...
For the Macintosh operating system, which was called System up to version 7. ...
Usually a program is made up of a (sometimes large) number of classes. So the logic and computation is distributed among these classes. However, as more classes are developed in a program, especially during maintenance and/or refactoring, the problem of communication between these classes may become more complex. In object-oriented programming, classes are used to group related variables and functions. ...
Logic, from Classical Greek λÏÎ³Î¿Ï (logos), originally meaning the word, or what is spoken, (but coming to mean thought or reason) is most often said to be the study of criteria for the evaluation of arguments, although the exact definition of logic is a matter of controversy among philosophers. ...
To meet Wikipedias quality standards, this article or section may require cleanup. ...
Maintenance see repair and maintenance Maintenance is a legal term of art that is used to describe child support and alimony (also called spousal support). ...
Refactoring is the process of rewriting a computer program or other material to improve its structure or readability, while explicitly keeping its meaning or behavior. ...
To meet Wikipedias quality standards, this article or section may require cleanup. ...
This makes the program harder to read and maintain. Furthermore, it can become difficult to change the program, since any change may affect code in several other classes. In software engineering, software maintenance is the process of enhancing and optimizing deployed software (software release), as well as remedying defects. ...
The Mediator pattern addresses this problem by promoting looser coupling between these classes by being the only class that has detailed knowledge of the methods of other classes. Classes send messages to the mediator when needed and the Mediator passes them on to any other classes that need to be informed. In computer science, coupling or dependency is the degree to which each program module relies on each other module. ...
Examples
Java The following Java program illustrates the Mediator pattern. It outputs: Sending message from kim to toni: Hello world. Received message by toni: Hello world. Sending message from rene to kim: Greetings! Headline text Received message by kim: Greetings! import java.util.*; interface Mediator { public void send(String id, String message); } class ConcreteMediator implements Mediator { private Map<String, Colleague> colleagues = new HashMap<String, Colleague>(); public void registerColleague(Colleague c) { c.registerMediator(this); colleagues.put(c.getId(), c); } public void send(String id, String message) { colleagues.get(id).receive(message); } } class Colleague { private Mediator mediator; private String id; public Colleague(String id) { this.id = id; } public void registerMediator(Mediator mediator) { this.mediator = mediator; } public String getId() { return id; } public void send(String id, String message) { System.out.println("Sending message from "+this.id+" to "+id+": "+message); mediator.send(id, message); // Dispatch the actual communication to the mediator!!! } public void receive(String message) { System.out.println("Received message by "+id+": "+message); } } class MediatorExample { public static void main(String[] args) { Colleague rene = new Colleague("rene"); Colleague toni = new Colleague("toni"); Colleague kim = new Colleague("kim"); ConcreteMediator m = new ConcreteMediator(); m.registerColleague(rene); m.registerColleague(toni); m.registerColleague(kim); kim.send("toni", "Hello world."); rene.send("kim", "Greetings!"); } } C# using System; using System.Collections; namespace ConsoleApplicationTest { public interface IMediator{ void Send(string id, string message); } /// <summary> /// All the participants exchanging messages in our system should implement this interface /// </summary> public interface IParticipant{ string Id{ get; set; } IMediator Mediator{ set; } void Send(string id, string message); void Receive(string message); } public class ConcreteMediator : IMediator{ Hashtable participants = new Hashtable(); public void RegisterParticipant(IParticipant c){ c.Mediator=this; participants.Add(c.Id, c); } public void Send(string id, string message){ ((IParticipant)participants[id]).Receive(message); } } /// <summary> /// Concrete participant 1 /// </summary> public class Colleague : IParticipant{ private IMediator mediator; private string id; public Colleague(string id){this.id = id;} public string Id{ get{return id;} set{id=value;} } public IMediator Mediator{ set{mediator=value;} } public void Send(string id, string message){ System.Console.WriteLine("Colleague: Sending message from "+this.id+" to "+id+": "+message); mediator.Send(id, message); // Dispatch the actual communication to the mediator!!! } public void Receive(string message){ System.Console.WriteLine("Colleague: Received message by "+id+": "+message); } } /// <summary> /// Concrete participant 2 /// </summary> public class NonColleague : IParticipant{ private IMediator mediator; private string id; public IMediator Mediator{ set{mediator=value;} } public string Id{ get{return id;} set{id=value;} } public NonColleague(string id){this.id = id;} public void Send(string id, string message){ System.Console.WriteLine("NonColleague: Sending message from "+this.id+" to "+id+": "+message); mediator.Send(id, message); // Dispatch the actual communication to the mediator!!! } public void Receive(string message){ System.Console.WriteLine("NonColleague: Received message by "+id+": "+message); } } public class MediatorExample { [STAThread] public static void Main(string[] args){ IParticipant rene = new Colleague("rene"); IParticipant toni = new Colleague("toni"); IParticipant kim = new NonColleague("kim"); ConcreteMediator m = new ConcreteMediator(); m.RegisterParticipant(rene); m.RegisterParticipant(toni); m.RegisterParticipant(kim); kim.Send("toni", "Hello world."); rene.Send("kim", "Greetings!"); Console.Read(); } } } The output will look like: NonColleague: Sending message from kim to toni: Hello world. Colleague: Received message by toni: Hello world. Colleague: Sending message from rene to kim: Greetings! NonColleague: Received message by kim: Greetings! Creational: Abstract factory • Builder • Factory • Prototype • Singleton {{Hide = {{{ Hybrid reference style allows grouped references at top, but uses m:Cite. ...
This article is about the book by Gamma et al. ...
A software design pattern, the Abstract Factory Pattern provides a way to encapsulate a group of individual factories that have a common theme. ...
Oftentimes, builder pattern builds Composite pattern, a structure pattern. ...
The Factory Method pattern is an object-oriented design pattern. ...
A prototype pattern is a creational design pattern used in software development when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. ...
In software engineering, the singleton design pattern is used to restrict instantiation of a class to one object. ...
Structural: Adapter • Bridge • Composite • Decorator • Façade • Flyweight • Proxy In computer programming, the adapter design pattern adapts one interface for a class into one that a client expects. ...
The bridge pattern is a design pattern used in software engineering which is meant to decouple an abstraction from its implementation so that the two can vary independently (Gamma et. ...
This article needs to be cleaned up to conform to a higher standard of quality. ...
In object-oriented programming, a decorator pattern is a design pattern. ...
The façade pattern is an object-oriented design pattern. ...
Flyweight is a software design pattern. ...
In computer programming, a proxy pattern is a software design pattern. ...
Behavorial: Chain of responsibility • Command • Interpreter • Iterator • Mediator • Memento • Observer • State • Strategy • Template method • Visitor In computer programming, chain-of-responsibility pattern is a design patterns where command objects are coming from somewhere, their processing logic is spread between a number of objects and the commands are distributed among those objects. ...
In object-oriented programming, the Command pattern is a design pattern in which objects are used to represent actions. ...
In computer programming, the interpreter pattern is a particular design pattern. ...
In object-oriented programming, an iterator is an object allowing one to sequence through all of the elements or parts contained in some other object, typically a container or list. ...
The memento pattern is a software design pattern that provides the ability to restore an object to its previous state (undo by rollback). ...
The observer pattern (sometimes known as publish subscribe) is a design pattern used in computer programming to observe the state of an object in a program. ...
A behavioral software design pattern, state pattern is used in computer programming to represent the state of an object. ...
In computer programming, the strategy pattern is a particular software design pattern, whereby algorithms can be selected on-the-fly at runtime depending on conditions, like strategies in a war situation. ...
Template method: UML class diagram. ...
In object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object structure. ...
|