Cam Quach Joel Derstine

10
Cam Quach Joel Derstine Mediator: Object Mediator: Object Behavioral Behavioral

description

Mediator: Object Behavioral. Cam Quach Joel Derstine. Intent. Mediator is an object to coordinate state changes between other objects Mediator promotes loose coupling by preventing objects from referring to each other explicitly - PowerPoint PPT Presentation

Transcript of Cam Quach Joel Derstine

Page 1: Cam Quach Joel Derstine

Cam QuachJoel Derstine

Mediator: Object Mediator: Object BehavioralBehavioral

Page 2: Cam Quach Joel Derstine

Intent• MediatorMediator is an object to

coordinate state changes between other objects

• MediatorMediator promotes loose coupling by preventing objects from referring to each other explicitly

• MediatorMediator allows designers to vary their interactions independently

Page 3: Cam Quach Joel Derstine

Problem• Goal in OO design is

to distribute behavior among objects

• Distribution will increase reusability

# of objects

interconnections

reusability

reusability

Page 4: Cam Quach Joel Derstine

Mediator

ConcreteMediator ConcreteColleague1 ConcreteColleague2

Colleague

SolutionsSolutions

Structure• Mediator Mediator provides an interface for communicating with Colleague objects• ConcreteMediatorMediator implements a cooperative behavior by coordinating the Colleague objects• Colleagues send and receive requests from a Mediator object

mediator

Page 5: Cam Quach Joel Derstine

A Conceptual Example:

The Problem• Multiple aircraft in the air space of an airport need to communicate with each other about changes in (some of) their properties (speed, altitude, direction).

• Where do the complexities reside if they tried to do this by communicating with each other directly?

Duell, “Non-software examples of software design patterns”, Object Magazine, July 1997

Page 6: Cam Quach Joel Derstine

Some complexities?• Who do they need to contact• When (or how often) do they need to contact• What do they need to tell them

Duell, “Non-software examples of software design patterns”, Object Magazine, July 1997

?

A Conceptual Example:

The Problem

I’m landing!

Not yet! I’m still taking off!!

Page 7: Cam Quach Joel Derstine

A Control Tower (the “mediator”)!Manages the complexity of communications:• Who to contact (observer object?)• When to contact• What to say

Duell, “Non-software examples of software design patterns”, Object Magazine, July 1997

?

A Conceptual Example:

A Solution

Page 8: Cam Quach Joel Derstine

GOF, “Design Patterns”, 1995

A Technical Example: The Problem

• How should the widgets on this dialog box communicate?

• What are the dependencies?• Each widget knows how to do its job. But should

it know how it fits into the larger picture?

Some issues/questions:

Page 9: Cam Quach Joel Derstine

GOF, “Design Patterns”, 1995

A Technical Example:

A SolutionCreate a FontDialogDirector Mediator!• Knows the widgets in the dialog box• Serves as the intermediary (widgets only

know about the mediator).• Coordinates their interaction

DialogDirector

ShowDialog()CreateWidgets()WidgetChanged(Widget)

FontDialogDirector

CreateWidgets()WidgetChanged(Widget)

Widget

Changed()

ListBox

GetSelection() EntryField

SetText()

director

list

field

Page 10: Cam Quach Joel Derstine

ConsequencesMediatorMediator• Limits subclassing • Decouples colleagues• Simplifies object

protocols• Abstracts how objects

cooperate• Centralizes control