PATTERN PRESENTATION MEDIATOR Claire Herdeman February 4 2019
PATTERN PRESENTATION: MEDIATOR Claire Herdeman February 4, 2019
PURPOSE The purpose of the Mediator design pattern is to define and manage communication between colleague objects when communication is welldefined but potentially complex (e. g. , dialogue box or air traffic control)
PARTICIPANTS • Mediator • Abstract mediator class defining communication interface between colleagues • Optional if there is only one mediator • Concrete Mediator (Ground Control) • Implements communication behavior between colleague classes • Colleague Classes (Flight, Runway) • Each knows the concrete mediator • Communicates with mediator rather than colleague • Can be subclasses of an abstract Colleague class
GENERAL STRUCTURE Mediator Concrete Mediator Colleague Concrete Colleague 1 Concrete Colleague 2
EXAMPLE STRUCTURE Abstract. Air Ground. Control. Mediator - Flight - Runway + land (Boolean) land - mediator + land() + register. Runway() + register. Flight() + is. Landing. Ok() + set. Landing. Status() Flight Runway + land() + get. Ready() + land() is. Landing. Ok set. Landing. Status
CHARACTERISTICS 1. Centralizes control – complex communication between colleagues is traded for complexity in the mediator 2. Decouples colleagues – easier to reuse colleagues and mediator independently 3. Simplifies object protocols – replaces many-to-many relationships with one-to-many relationships which are easier to understand maintain 4. Abstracts object cooperation – mediation is considered independently from object, can clarify object interaction
- Slides: 6