Top Banner
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29
26

SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Dec 30, 2015

Download

Documents

Rose Washington
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

SOFTWARE DESIGN AND ARCHITECTURE

LECTURE 29

Page 2: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Review

• Design pattern classifications• Structural Design Pattern– Adapter Pattern

Page 3: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Outline

• Structural Design Patterns– Façade Pattern

Page 4: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Structural Patterns

• deal with the composition of classes or objects.

• Structural class patterns:– use inheritance to compose classes

• Structural object patterns:– describe ways to assemble objects.

Page 5: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

FAÇADE PATTERN

Page 6: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Façade Pattern

• Problem– There may be undesirable coupling to many things

in the subsystem, or the implementation of the subsystem may change.

– What to do?

Page 7: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Façade – Example (Home Theater)

Page 8: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Façade - Example• Starting the HomeTheater• Put the screen down• Turn on the projector• Dim the lights• Set the projector input to

DVD• Turn the amplifier on• Set the amplifier to DVD

input• Turn the DVD player on• Start the DVD Player playing

Page 9: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

• Turning everything off at the end• Complex task to listen music• When upgraded or new things added, you would have to

learn new steps

Page 10: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Lights, Camera, Façade!

• A Façade is what you need.• With the façade pattern, you can take a

complex subsystem and make it easier to use by implementing a façade class that provides a reasonable set of interfaces.

Page 11: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.
Page 12: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.
Page 13: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.
Page 14: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Watch a movie with ease

Page 15: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Façade - Definition

• Provides a unified interface to a set of interfaces in a sub-system.

• Defines a higher level interface that makes the subsystem easier to use.

Page 16: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Facade

• Problem– There may be undesirable coupling to many things in the

subsystem, or the implementation of the subsystem may change. What to do?

• Solution– Define a single point of contact to the subsystem facade

object that wraps the subsystem. – This facade object presents a single unified interface and is

responsible for collaborating with the subsystem components

Page 17: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Facade

Page 18: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Facade

Page 19: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Façade - Consequences

• It shields clients from subsystem components, thereby reducing the number of objects that clients deal with and making the subsystem easier to use

• It promotes weak coupling between the subsystem and its clients. Weak coupling lets you vary the components of the subsystem without affecting its clients

• It doesn't prevent applications from using subsystem classes if they need to.

Page 20: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.
Page 21: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Façade vs. Adapter• With both the Facade and Adapter pattern, we have

preexisting classes.• With the Facade, however, we do not have an interface we

must design to, as we do in the Adapter pattern.• We are not interested in polymorphic behavior with the

Facade; whereas with the Adapter, we probably are. • In the case of the Facade pattern, the motivation is to simplify

the interface. With the Adapter, although simpler is better, we try to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.

Page 22: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Façade Pattern - Example

Page 23: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Individual Classes

Page 24: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Façade Class

Page 25: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

*

Page 26: SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29. Review Design pattern classifications Structural Design Pattern – Adapter Pattern.

Summary

• Structural Design Patterns– Façade Pattern