The Faade Pattern SE2811 Dr Mark L Hornick

  • Slides: 9
Download presentation
The Façade Pattern SE-2811 Dr. Mark L. Hornick 1

The Façade Pattern SE-2811 Dr. Mark L. Hornick 1

Watching a Movie. . . Use multiple interfaces (remotes) to l Turn on Receiver/amplifier

Watching a Movie. . . Use multiple interfaces (remotes) to l Turn on Receiver/amplifier l Turn on TV/Monitor l Turnn on DVD player l Set the Receiver input to DVD l Put the Monitor in HDMI input mode l Set the Receiver volume to medium l Set Receiver to DTS Surround Interacting with the following classes: l Start the DVD player. • Receiver/Amplifier • TV/Monitor • DVD

To decrease the complexity. . We can create a new class Theater. Facade (e.

To decrease the complexity. . We can create a new class Theater. Facade (e. g. a universal remote) which exposes a few methods such as watch. Movie(). l The façade treats the various components as a sub system and calls on them to implement the watch. Movie method. l So to watch a movie, we just call one method, watch. Movie and it communicates with the Monitor, DVD, and Receiver for us. l The façade still leaves the subsystem accessible to be used directly. If you need the advanced functionality of the subsystem classes, they are available for use.

The Problem Complex system l l Consisting of multiple subsystems Each with its own

The Problem Complex system l l Consisting of multiple subsystems Each with its own interface, each with many methods Difficult for clients (blue) to deal with

Facade Solution l l l Centralize subsystem interface Simplify/reduce number of centralized methods Façade

Facade Solution l l l Centralize subsystem interface Simplify/reduce number of centralized methods Façade presents new unified “face” to clients Facade

Removing the burden from beginning Java developers with a Façade (Win. Plotter) SE-2811 Dr.

Removing the burden from beginning Java developers with a Façade (Win. Plotter) SE-2811 Dr. Mark L. Hornick 6

Generic Pattern SE-2811 Dr. Mark L. Hornick 7

Generic Pattern SE-2811 Dr. Mark L. Hornick 7

Facade Consequences Shields clients from subsystem components l Make subsystem easier to use Reduces

Facade Consequences Shields clients from subsystem components l Make subsystem easier to use Reduces coupling from client to subsystem classes l l l Allow internal classes to change freely Permit “layering” of system function Level of client-subsystem coupling l Make Facade an abstract class § l Different concrete subclasses for different implementations of the subsystem. Configure the façade object with different subsystem objects.

Facade Applications Interface to existing library l Unify or “clean up” complex interface Design

Facade Applications Interface to existing library l Unify or “clean up” complex interface Design layered system l l Various service levels Façade abstracts interface of each level Provide abstract interfaces l To alternative implementations