TAILIEUCHUNG - Lecture Software design and architecture – Chapter 29
In this chapter, the following content will be discussed: Design pattern classifications, structural design pattern, adapter pattern, structural design patterns, façade pattern, watch a movie with ease, façade - consequences, individual classes. | SOFTWARE DESIGN AND ARCHITECTURE LECTURE 29 Review Design pattern classifications Structural Design Pattern Adapter Pattern Outline Structural Design Patterns Façade 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. Façade 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? Façade – Example (Home Theater) 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 Turning everything off at the end Complex task to listen music When upgraded or new things added, you would have to learn new steps 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. Watch a movie with ease 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. 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 Facade Facade 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. 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. Façade Pattern - Example Individual Classes Façade Class * Summary Structural Design Patterns Façade Pattern
đang nạp các trang xem trước