Mediator - bYTEBoss

Download Report

Transcript Mediator - bYTEBoss

Mediator
A Behavioral Design Pattern for the
New Millennium
Cory Nugent
Designing for OOP

Goals of Object Oriented Design
Distribute behavior among different objects.
 Encourage code reuse
 Facilitate communication between objects

What’s the Problem?
Communication between objects
becomes too complicated.
 Changing system behavior becomes too
difficult.
 No central access points are available.

DAS MEDIATØR!
A class that controls interactions of a
group of other objects.
 Promotes loose coupling (Objects don’t
explicitly reference each other).
 Objects need only know about their
mediator.
 Provides a centralized behavior
management point.

The Good
Changing system behavior means subclassing the mediator.
 Mediator and Colleague classes are
independent of each other.
 Mediator-Colleague relationship is one to
many; Colleague-Colleague relationship
is many to many.
 Object interaction becomes easy to
understand.

The Bad
All object interactions are bundled into
the mediator.
 The mediator class can be complex and
hard to maintain.

How it all works
Diagram courtesy of Gopalan Suresh Raj
The Mediator

Mediator


Defines an interface for communicating with
colleague classes.
Concrete Mediator

Coordinates colleague objects
How it all works
Diagram courtesy of Gopalan Suresh Raj
The Colleagues

Colleague


Defines an interface for communicating with
mediator class.
Concrete Colleagues
Each colleague knows its mediator
 Each colleague communicates with its
mediator when it would otherwise
communicate with its colleague.

How it all works
Diagram courtesy of Gopalan Suresh Raj
There is no more presentation

Thank you, come again.