Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Broker Design Patterns: Façade and Mediator.

Similar presentations


Presentation on theme: "© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Broker Design Patterns: Façade and Mediator."— Presentation transcript:

1 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Broker Design Patterns: Façade and Mediator

2 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2 Objectives  To present the structure, behavior, and characteristics of broker patterns  To present the Façade and Mediator design patterns

3 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3 Topics  Broker patterns  The Façade pattern  The Mediator pattern

4 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4 Broker Pattern Structure  The Client must access the Broker and the Broker must access the Supplier  Most Broker patterns elaborate this basic structure

5 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5 Broker Pattern Behavior

6 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6 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.

7 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7 Broker Example: Iterator Form

8 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8 Broker Example: Iterator Behavior

9 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9 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

10 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 10 Façade Pattern Structure

11 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 11 Façade Examples  Interface to a compiler  Interface to a user interface (from the application side)  Interface to a memory management system

12 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 12 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).

13 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 13 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

14 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 14 Using a Mediator

15 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 15 Mediator Pattern Structure

16 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16 Mediator as a Broker

17 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 17 Mediator Behavior

18 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 18 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.

19 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19 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.

20 © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 20 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.


Download ppt "© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Broker Design Patterns: Façade and Mediator."

Similar presentations


Ads by Google