Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter Ten The Bridge Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.

Similar presentations


Presentation on theme: "Chapter Ten The Bridge Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh."— Presentation transcript:

1 Chapter Ten The Bridge Pattern Ku-Yaw Chang canseco@mail.dyu.edu.tw Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University

2 2Ku-Yaw ChangThe Bridge Pattern Outline Overview Introducing the Bridge Pattern Learning the Bridge Pattern: An Example An Observation About Using Design Patterns Learning the Bridge Pattern: Deriving It Field Notes: Using the Bridge Pattern Summary

3 3Ku-Yaw ChangThe Bridge Pattern Overview Provides an example to help you derive the Bridge pattern. Presents the key features of the pattern. Presents some observations on the Bridge pattern from my own practice

4 4Ku-Yaw ChangThe Bridge Pattern Outline Overview Introducing the Bridge Pattern Learning the Bridge Pattern: An Example An Observation About Using Design Patterns Learning the Bridge Pattern: Deriving It Field Notes: Using the Bridge Pattern Summary

5 5Ku-Yaw ChangThe Bridge Pattern Introducing the Bridge Pattern Intent To decouple an abstraction from its implementation so that the two can vary independently. To decouple an abstraction from its implementation so that the two can vary independently.

6 6Ku-Yaw ChangThe Bridge Pattern Outline Overview Introducing the Bridge Pattern Learning the Bridge Pattern: An Example An Observation About Using Design Patterns Learning the Bridge Pattern: Deriving It Field Notes: Using the Bridge Pattern Summary

7 7Ku-Yaw ChangThe Bridge Pattern Learning the Bridge Pattern: An Example A simple problem Drawing shapes Drawing shapesRectangles Different drawing programs Different drawing programs

8 8Ku-Yaw ChangThe Bridge Pattern Learning the Bridge Pattern: An Example Proper use of inheritance We don’t want the code that draws the rectangles to worry about what type of drawing program it should use. We don’t want the code that draws the rectangles to worry about what type of drawing program it should use. V1Rectangle uses DP1 V2Rectangle uses DP2 Changing requirements: add a new shape - circle Changing requirements: add a new shape - circle

9 9Ku-Yaw ChangThe Bridge Pattern Learning the Bridge Pattern: An Example Design with inheritance

10 10Ku-Yaw ChangThe Bridge Pattern Learning the Bridge Pattern: An Example Sequence diagram

11 11Ku-Yaw ChangThe Bridge Pattern Learning the Bridge Pattern: An Example Combinatorial explosion Another new drawing program Another new drawing program Six different kinds of Shapes 2 Shape concepts times three drawing programs 2 Shape concepts times three drawing programs Another type of Shape Another type of Shape Nine different kinds of Shapes 3 Shape concepts times three drawing programs 3 Shape concepts times three drawing programs

12 12Ku-Yaw ChangThe Bridge Pattern Learning the Bridge Pattern: An Example Reason Tightly coupled Tightly coupled The abstraction ( the kinds of Shapes ) and the implementation ( the drawing programs)

13 13Ku-Yaw ChangThe Bridge Pattern Learning the Bridge Pattern: An Example The Bridge pattern To decouple an abstraction from its implementation so that the two can vary independently To decouple an abstraction from its implementation so that the two can vary independently Abstraction 1 Implementation A Abstraction 2 Implementation B Abstraction 3 Implementation C...…

14 14Ku-Yaw ChangThe Bridge Pattern Outline Overview Introducing the Bridge Pattern Learning the Bridge Pattern: An Example An Observation About Using Design Patterns Learning the Bridge Pattern: Deriving It Field Notes: Using the Bridge Pattern Summary

15 15Ku-Yaw ChangThe Bridge Pattern An Observation About Using Design Patterns A new way to look at design patterns Focus on the context of the pattern – the problem it is trying to solve Focus on the context of the pattern – the problem it is trying to solve Not on the solutions the patterns offer The bridge pattern An abstraction that has different implementations An abstraction that has different implementations Allow the abstraction and the implementation to vary independently of each other Allow the abstraction and the implementation to vary independently of each other

16 16Ku-Yaw ChangThe Bridge Pattern Outline Overview Introducing the Bridge Pattern Learning the Bridge Pattern: An Example An Observation About Using Design Patterns Learning the Bridge Pattern: Deriving It Field Notes: Using the Bridge Pattern Summary

17 17Ku-Yaw ChangThe Bridge Pattern Learning the Bridge Pattern: Deriving It A new paradigm for finding objects Commonality Commonality Variability Variability Strategies to handle variation Find what varies and encapsulate it Find what varies and encapsulate it Favor aggregation over inheritance Favor aggregation over inheritance

18 18Ku-Yaw ChangThe Bridge Pattern Learning the Bridge Pattern: Deriving It Represent the variations

19 19Ku-Yaw ChangThe Bridge Pattern Learning the Bridge Pattern: Deriving It Tying the classes together What uses what? What uses what?

20 20Ku-Yaw ChangThe Bridge Pattern Learning the Bridge Pattern: Deriving It Expanding the design

21 21Ku-Yaw ChangThe Bridge Pattern Separation of abstraction and implementation

22 22Ku-Yaw ChangThe Bridge Pattern Outline Overview Introducing the Bridge Pattern Learning the Bridge Pattern: An Example An Observation About Using Design Patterns Learning the Bridge Pattern: Deriving It Field Notes: Using the Bridge Pattern Summary

23 23Ku-Yaw ChangThe Bridge Pattern Field Notes: Using the Bridge Pattern The Bridge pattern often incorporates the Adapter pattern Compound design patterns Compound design patterns Instantiating the objects of the Bridge pattern The objects representing the abstraction were given their implementation while being instantiated. The objects representing the abstraction were given their implementation while being instantiated.

24 24Ku-Yaw ChangThe Bridge Pattern Field Notes: Using the Bridge Pattern Generic structure of the Bridge pattern

25 25Ku-Yaw ChangThe Bridge Pattern Outline Overview Introducing the Bridge Pattern Learning the Bridge Pattern: An Example An Observation About Using Design Patterns Learning the Bridge Pattern: Deriving It Field Notes: Using the Bridge Pattern Summary

26 26Ku-Yaw ChangThe Bridge Pattern Summary Basic strategies for dealing with variation: Find what varies and encapsulate it. Find what varies and encapsulate it. Favor aggregation over inheritance. Favor aggregation over inheritance. More effective in picking patterns that will help you Understand whys and whats of the patterns Understand whys and whats of the patterns

27 The End


Download ppt "Chapter Ten The Bridge Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh."

Similar presentations


Ads by Google