FACTOID # 133: The top 10 countries for electricity generation using a nuclear energy source are all in Europe.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Mediator pattern

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. ...

Contents

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! 

  Results from FactBites:
 
Design Pattern Synopses (4381 words)
The Filter pattern is a special case of the Decorator pattern, where a data source or data sink object is wrapped to add logic to the handling of a data stream.
The Composite pattern also allows the objects in the tree to be manipulated in a consistent manner, by requiring all of the objects in the tree to have a common superclass or interface.
The Flyweight pattern is often combined with the Composite pattern to represent the leaf nodes of a hierarchical structure with shared objects.
Mediator pattern - Wikipedia, the free encyclopedia (199 words)
The mediator pattern is a software design pattern that provides a unified interface to a set of interfaces in a subsystem.
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.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.