SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Mediator Pattern
(A Behavioral Pattern)
Mediator
Motivation
 Object-oriented design encourages the distribution of
   behavior among objects. Such distribution can result in an
   object structure with many connections between objects;
   in the worst case, every object ends up knowing about
   every other.

 As an example, consider the implementation of dialog
   boxes in a graphical user interface. A dialog box uses a
   window to present a collection of widgets such as buttons,
   menus, and entry fields, as shown here:

 Often there are dependencies between the widgets in the
   dialog. For example, a button gets disabled when a certain
   entry field is empty. Selecting an entry in a list of choices
   called a list box might change the contents of an entry
   field. Conversely, typing text into the entry field might
   automatically select one or more corresponding entries in
   the list box. Once text appears in the entry field, other
   buttons may become enabled that let the user do
   something with the text, such as changing or deleting the
   thing to which it refers.
Motivation
 Different dialog boxes will have different dependencies between widgets. So
  even though dialogs display the same kinds of widgets, they can't simply reuse
  stock widget classes.

 You can avoid these problems by encapsulating collective behavior in a
  separate mediator object. A mediator is responsible for controlling and
  coordinating the interactions of a group of objects. The mediator serves as an
  intermediary that keeps objects in the group from referring to each other
  explicitly. The objects only know the mediator, thereby reducing the number
  of interconnections.

 For example, FontDialogDirector can be the mediator between the widgets
  in a dialog box. A FontDialogDirector object knows the widgets in a dialog and
  coordinates their interaction. It acts as a hub of communication for widgets.
Motivation
Motivation
 Here's the succession of events by which a list box's selection passes
  to an entry field:

    The list box tells its director that it's changed.
    The director gets the selection from the list box.
    The director passes the selection to the entry field.
    Now that the entry field contains some text, the director enables
     button(s) for initiating an action (e.g., "demibold," "oblique").

 Note how the director mediates between the list box and the entry
  field. Widgets communicate with each other only indirectly, through
  the director. They don't have to know about each other; all they know
  is the director. Furthermore, because the behavior is localized in one
  class, it can be changed or replaced by extending or replacing that
  class.
Motivation
 Here's how the FontDialogDirector abstraction can be integrated into a class library:




 DialogDirector is an abstract class that defines the overall behavior of a dialog. Clients
   call the ShowDialog operation to display the dialog on the screen. CreateWidgets is an
   abstract operation for creating the widgets of a dialog. WidgetChanged is another
   abstract operation; widgets call it to inform their director that they have changed.
   DialogDirector subclasses override CreateWidgets to create the proper widgets, and
   they override WidgetChanged to handle the changes.
Applicability
Use the Mediator pattern when

   a set of objects communicate in well-defined but complex ways.
    The resulting interdependencies are unstructured and difficult
    to understand.
   reusing an object is difficult because it refers to and
    communicates with many other objects.
   a behavior that's distributed between several classes should be
    customizable without a lot of subclassing.
Structure
Participants
Mediator (DialogDirector)
   defines an interface for communicating with Colleague objects.

ConcreteMediator (FontDialogDirector)
   implements cooperative behavior by coordinating Colleague
    objects.
   knows and maintains its colleagues.

Colleague classes (ListBox, EntryField)
   each Colleague class knows its Mediator object.
   each colleague communicates with its mediator whenever it would
    have otherwise communicated with another colleague.
Collaborations
Colleagues send and receive requests from
 a Mediator object. The mediator
 implements the cooperative behavior by
 routing requests between the appropriate
 colleague(s).
Consequences
 The Mediator pattern has the following benefits and drawbacks:

     It limits subclassing. A mediator localizes behavior that otherwise would be distributed
       among several objects. Changing this behavior requires subclassing Mediator only;
       Colleague classes can be reused as is.

     It decouples colleagues. A mediator promotes loose coupling between colleagues. You can
       vary and reuse Colleague and Mediator classes independently.

     It simplifies object protocols. A mediator replaces many-to-many interactions with one-
       to-many interactions between the mediator and its colleagues. One-to-many
       relationships are easier to understand, maintain, and extend.

     It abstracts how objects cooperate. Making mediation an independent concept and
       encapsulating it in an object lets you focus on how objects interact apart from their
       individual behavior. That can help clarify how objects interact in a system.

     It centralizes control. The Mediator pattern trades complexity of interaction for
       complexity in the mediator. Because a mediator encapsulates protocols, it can become
       more complex than any individual colleague. This can make the mediator itself a
       monolith that's hard to maintain.
Implementation
 The following implementation issues are relevant to the Mediator pattern:

    Omitting the abstract Mediator class. There's no need to define an abstract
      Mediator class when colleagues work with only one mediator. The abstract
      coupling that the Mediator class provides lets colleagues work with different
      Mediator subclasses, and vice versa.

    Colleague-Mediator communication. Colleagues have to communicate with
      their mediator when an event of interest occurs. One approach is to
      implement the Mediator as an Observer using the Observer pattern. Colleague
      classes act as Subjects, sending notifications to the mediator whenever they
      change state. The mediator responds by propagating the effects of the change
      to other colleagues.

    Another approach defines a specialized notification interface in Mediator that
      lets colleagues be more direct in their communication. Smalltalk/V for
      Windows uses a form of delegation: When communicating with the mediator,
      a colleague passes itself as an argument, allowing the mediator to identify the
      sender. The Sample Code uses this approach, and the Smalltalk/V
      implementation is discussed further in the Known Uses.
Sample Code
Sample Code
Sample Code
Assignment
 Develop a calendar application to remind us tasks to do. When a
  reminder triggers, it shows a notification alarm / popup. In the
  notification, we can select snooze or close. If we select snooze, then
  after a certain time span(15 Min) the alarm will notify us again. If we
  don’t respond to the notification in 30 seconds it automatically goes
  into snooze mode. The alarm automatically closes, if it goes into
  snooze mode for 3 times and logs the failure.

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

interface in c#
interface in c#interface in c#
interface in c#
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Pengenalan ReactJS
Pengenalan ReactJS Pengenalan ReactJS
Pengenalan ReactJS
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Objects and classes in Visual Basic
Objects and classes in Visual BasicObjects and classes in Visual Basic
Objects and classes in Visual Basic
 
Java Beans
Java BeansJava Beans
Java Beans
 
Facade Pattern
Facade PatternFacade Pattern
Facade Pattern
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
ADF Bindings & Data Controls
ADF Bindings & Data ControlsADF Bindings & Data Controls
ADF Bindings & Data Controls
 
Class and object
Class and objectClass and object
Class and object
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion Principle
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 

Andere mochten auch

Andere mochten auch (13)

Mediator
MediatorMediator
Mediator
 
Mediator Pattern
Mediator PatternMediator Pattern
Mediator Pattern
 
Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)
 
Memento pattern
Memento patternMemento pattern
Memento pattern
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibility
 
The Decorator Pattern
The Decorator PatternThe Decorator Pattern
The Decorator Pattern
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Observer Pattern
Observer PatternObserver Pattern
Observer Pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 

Ähnlich wie Mediator pattern

Software Design Patterns - An Overview
Software Design Patterns - An OverviewSoftware Design Patterns - An Overview
Software Design Patterns - An OverviewFarwa Ansari
 
SAD05 - Encapsulation
SAD05 - EncapsulationSAD05 - Encapsulation
SAD05 - EncapsulationMichael Heron
 
Design Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityDesign Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityShubham Narkhede
 
Software Patterns
Software PatternsSoftware Patterns
Software Patternsbonej010
 
Architecture and design
Architecture and designArchitecture and design
Architecture and designhimanshu_airon
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UMLyndaravind
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Luis Valencia
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questionsjinaldesailive
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented PrinciplesEmprovise
 
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design PatternsNina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design Patternsiasaglobal
 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and oodthan sare
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design PatternsFaizan Haider
 

Ähnlich wie Mediator pattern (20)

Software Design Patterns - An Overview
Software Design Patterns - An OverviewSoftware Design Patterns - An Overview
Software Design Patterns - An Overview
 
Design patterns
Design patternsDesign patterns
Design patterns
 
C# concepts
C# conceptsC# concepts
C# concepts
 
SAD05 - Encapsulation
SAD05 - EncapsulationSAD05 - Encapsulation
SAD05 - Encapsulation
 
Design Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityDesign Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur University
 
01. design pattern
01. design pattern01. design pattern
01. design pattern
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Architecture and design
Architecture and designArchitecture and design
Architecture and design
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
 
Sda 9
Sda   9Sda   9
Sda 9
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
 
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design PatternsNina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and ood
 
Sda 7
Sda   7Sda   7
Sda 7
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design Patterns
 
Mediator.pptx
Mediator.pptxMediator.pptx
Mediator.pptx
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 

Mehr von Shakil Ahmed

Mehr von Shakil Ahmed (16)

B-tree & R-tree
B-tree & R-treeB-tree & R-tree
B-tree & R-tree
 
Advanced data structure
Advanced data structureAdvanced data structure
Advanced data structure
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 
Command pattern
Command patternCommand pattern
Command pattern
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
iOS 5
iOS 5iOS 5
iOS 5
 
Ios development
Ios developmentIos development
Ios development
 
Graph
GraphGraph
Graph
 
Lowest common ancestor
Lowest common ancestorLowest common ancestor
Lowest common ancestor
 
Segment tree
Segment treeSegment tree
Segment tree
 
Tree & bst
Tree & bstTree & bst
Tree & bst
 
Trie tree
Trie treeTrie tree
Trie tree
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Advanced Search Techniques
Advanced Search TechniquesAdvanced Search Techniques
Advanced Search Techniques
 

Kürzlich hochgeladen

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Kürzlich hochgeladen (20)

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Mediator pattern

  • 3. Motivation  Object-oriented design encourages the distribution of behavior among objects. Such distribution can result in an object structure with many connections between objects; in the worst case, every object ends up knowing about every other.  As an example, consider the implementation of dialog boxes in a graphical user interface. A dialog box uses a window to present a collection of widgets such as buttons, menus, and entry fields, as shown here:  Often there are dependencies between the widgets in the dialog. For example, a button gets disabled when a certain entry field is empty. Selecting an entry in a list of choices called a list box might change the contents of an entry field. Conversely, typing text into the entry field might automatically select one or more corresponding entries in the list box. Once text appears in the entry field, other buttons may become enabled that let the user do something with the text, such as changing or deleting the thing to which it refers.
  • 4. Motivation  Different dialog boxes will have different dependencies between widgets. So even though dialogs display the same kinds of widgets, they can't simply reuse stock widget classes.  You can avoid these problems by encapsulating collective behavior in a separate mediator object. A mediator is responsible for controlling and coordinating the interactions of a group of objects. The mediator serves as an intermediary that keeps objects in the group from referring to each other explicitly. The objects only know the mediator, thereby reducing the number of interconnections.  For example, FontDialogDirector can be the mediator between the widgets in a dialog box. A FontDialogDirector object knows the widgets in a dialog and coordinates their interaction. It acts as a hub of communication for widgets.
  • 6. Motivation  Here's the succession of events by which a list box's selection passes to an entry field:  The list box tells its director that it's changed.  The director gets the selection from the list box.  The director passes the selection to the entry field.  Now that the entry field contains some text, the director enables button(s) for initiating an action (e.g., "demibold," "oblique").  Note how the director mediates between the list box and the entry field. Widgets communicate with each other only indirectly, through the director. They don't have to know about each other; all they know is the director. Furthermore, because the behavior is localized in one class, it can be changed or replaced by extending or replacing that class.
  • 7. Motivation  Here's how the FontDialogDirector abstraction can be integrated into a class library:  DialogDirector is an abstract class that defines the overall behavior of a dialog. Clients call the ShowDialog operation to display the dialog on the screen. CreateWidgets is an abstract operation for creating the widgets of a dialog. WidgetChanged is another abstract operation; widgets call it to inform their director that they have changed. DialogDirector subclasses override CreateWidgets to create the proper widgets, and they override WidgetChanged to handle the changes.
  • 8. Applicability Use the Mediator pattern when  a set of objects communicate in well-defined but complex ways. The resulting interdependencies are unstructured and difficult to understand.  reusing an object is difficult because it refers to and communicates with many other objects.  a behavior that's distributed between several classes should be customizable without a lot of subclassing.
  • 10. Participants Mediator (DialogDirector)  defines an interface for communicating with Colleague objects. ConcreteMediator (FontDialogDirector)  implements cooperative behavior by coordinating Colleague objects.  knows and maintains its colleagues. Colleague classes (ListBox, EntryField)  each Colleague class knows its Mediator object.  each colleague communicates with its mediator whenever it would have otherwise communicated with another colleague.
  • 11. Collaborations Colleagues send and receive requests from a Mediator object. The mediator implements the cooperative behavior by routing requests between the appropriate colleague(s).
  • 12. Consequences  The Mediator pattern has the following benefits and drawbacks:  It limits subclassing. A mediator localizes behavior that otherwise would be distributed among several objects. Changing this behavior requires subclassing Mediator only; Colleague classes can be reused as is.  It decouples colleagues. A mediator promotes loose coupling between colleagues. You can vary and reuse Colleague and Mediator classes independently.  It simplifies object protocols. A mediator replaces many-to-many interactions with one- to-many interactions between the mediator and its colleagues. One-to-many relationships are easier to understand, maintain, and extend.  It abstracts how objects cooperate. Making mediation an independent concept and encapsulating it in an object lets you focus on how objects interact apart from their individual behavior. That can help clarify how objects interact in a system.  It centralizes control. The Mediator pattern trades complexity of interaction for complexity in the mediator. Because a mediator encapsulates protocols, it can become more complex than any individual colleague. This can make the mediator itself a monolith that's hard to maintain.
  • 13. Implementation  The following implementation issues are relevant to the Mediator pattern:  Omitting the abstract Mediator class. There's no need to define an abstract Mediator class when colleagues work with only one mediator. The abstract coupling that the Mediator class provides lets colleagues work with different Mediator subclasses, and vice versa.  Colleague-Mediator communication. Colleagues have to communicate with their mediator when an event of interest occurs. One approach is to implement the Mediator as an Observer using the Observer pattern. Colleague classes act as Subjects, sending notifications to the mediator whenever they change state. The mediator responds by propagating the effects of the change to other colleagues.  Another approach defines a specialized notification interface in Mediator that lets colleagues be more direct in their communication. Smalltalk/V for Windows uses a form of delegation: When communicating with the mediator, a colleague passes itself as an argument, allowing the mediator to identify the sender. The Sample Code uses this approach, and the Smalltalk/V implementation is discussed further in the Known Uses.
  • 17. Assignment  Develop a calendar application to remind us tasks to do. When a reminder triggers, it shows a notification alarm / popup. In the notification, we can select snooze or close. If we select snooze, then after a certain time span(15 Min) the alarm will notify us again. If we don’t respond to the notification in 30 seconds it automatically goes into snooze mode. The alarm automatically closes, if it goes into snooze mode for 3 times and logs the failure.