Broker Design Patterns Faade and Mediator 2007 Pearson
Broker Design Patterns: Façade and Mediator © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Objectives § To present the structure, behavior, and characteristics of broker patterns § To present the Façade and Mediator design patterns © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Topics § Broker patterns § The Façade pattern § The Mediator pattern © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Broker Pattern Structure § The Client must access the Broker and the Broker must access the Supplier § Most Broker patterns elaborate this basic structure © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Broker Pattern Behavior © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Broker Pattern Advantages § Simplify the Supplier—A Broker can augment the Supplier’s services. § Decompose the Supplier—A complex Supplier can offload some of its responsibilities to a Broker. § Facilitate Client/Supplier Interaction—A Broker may present a different interface, handle interaction details, etc. © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Broker Example: Iterator Form © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Broker Example: Iterator Behavior © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Façade Pattern § The Façade pattern eases interaction between a client and a sub-system of suppliers by providing a simpler interface to the sub-system. § The broker class is a façade that provides simplified sub-system services to clients. § Analogy: a travel agent © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Façade Pattern Structure © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Façade Examples § Interface to a compiler § Interface to a user interface (from the application side) § Interface to a memory management system © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
When to Use a Façade § Use the Façade pattern when there is a need to provide a simplified interface to a complex sub-system. § Façades can also help decouple systems. • If the façade mediates all interaction with a client, then the sub-system can be changed without affecting the client. § A façade may work like an adapter by providing a new interface to a sub-system (adapters are discussed later). © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Mediator Pattern § The Mediator pattern reduces coupling and simplifies code when several objects must negotiate a complex interaction. § Classes interact only with a mediator class rather than with each other. § Classes are coupled only to the mediator where interaction control code resides. § Mediator is like a multi-way Façade pattern. § Analogy: a meeting scheduler © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Using a Mediator © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Mediator Pattern Structure © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Mediator as a Broker © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Mediator Behavior © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
When to Use a Mediator § Use the Mediator pattern when a complex interaction between collaborators must be encapsulated to • Decouple collaborators, • Centralize control of an interaction, and • Simplify the collaborators. § Using a mediator may compromise performance. © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Mediators, Façades, and Control Styles § The Façade and Mediator patterns provide means to make control more centralized. § The Façade and Mediator patterns should be used to move from a dispersed to a delegated style, but not from a delegated to a centralized style. © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Summary § Broker patterns use a Broker class to facilitate the interaction between a Client and a Supplier. § The Façade pattern uses a broker (the façade) to provide a simplified interface to a complex sub-system. § The Mediator pattern uses a broker to encapsulate and control a complex interaction among several suppliers. © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
- Slides: 20