Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter Five An Introduction to Design Patterns Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information.

Similar presentations


Presentation on theme: "Chapter Five An Introduction to Design Patterns Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information."— Presentation transcript:

1 Chapter Five An Introduction to Design Patterns Ku-Yaw Chang canseco@mail.dyu.edu.tw Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University

2 2Ku-Yaw ChangThe Object-Oriented Paradigm Outline Overview Design Patterns Arose from Architecture and Anthropology Moving from Architectural to Software Design Patterns Why Study Design Patterns? Other Advantages to Studying Design Patterns Summary

3 3Ku-Yaw ChangThe Object-Oriented Paradigm Overview Design patterns Cutting edge of the OO technology Cutting edge of the OO technologyRelationships Master OO skills first, then learn design patterns Master OO skills first, then learn design patterns The opposite is also true The opposite is also true Learning design patterns early in the learning of object- oriented skills greatly helps to improve understanding of object-oriented analysis and design. Design patterns and OO design reinforce each other Design patterns and OO design reinforce each other Many ideas are from Christopher Alexander’s Timeless Way of Building Christopher Alexander’s Timeless Way of Building

4 4Ku-Yaw ChangThe Object-Oriented Paradigm Outline Overview Design Patterns Arose from Architecture and Anthropology Moving from Architectural to Software Design Patterns Why Study Design Patterns? Other Advantages to Studying Design Patterns Summary

5 5Ku-Yaw ChangThe Object-Oriented Paradigm Design Patterns Arose from Architecture and Anthropology Christopher Alexander asked himself Is quality objective? Is quality objective? What makes us know when an architectural design is good? What makes us know when an architectural design is good? Alexander postulates There is such an objective basis within architectural systems. There is such an objective basis within architectural systems. We can describe beauty through an objective basis that can be measured. We can describe beauty through an objective basis that can be measured.

6 6Ku-Yaw ChangThe Object-Oriented Paradigm Design Patterns Arose from Architecture and Anthropology If quality in design is objective Be able to identify what makes designs good and what makes designs bad Be able to identify what makes designs good and what makes designs bad Alexander asked What is present in a good quality design that is not present in a poor quality design? What is present in a good quality design that is not present in a poor quality design? What is present in a poor quality design that is not present in a good quality design? What is present in a poor quality design that is not present in a good quality design? Alexander discovered Good constructs had things in common with each other Good constructs had things in common with each other

7 7Ku-Yaw ChangThe Object-Oriented Paradigm Design Patterns Arose from Architecture and Anthropology Two porches may appear structurally different appear structurally different solve the same (or similar) problem solve the same (or similar) problem be considered high quality be considered high quality

8 8Ku-Yaw ChangThe Object-Oriented Paradigm Design Patterns Arose from Architecture and Anthropology Alexander narrowed his focus Look at structures that solve similar problems Look at structures that solve similar problems Discern similarities between designs that were high quality Discern similarities between designs that were high quality These similarities are called patterns These similarities are called patterns A solution to a problem in a context Each pattern describes a problem which occurs over and over again in our environment and then describes the core of the solution to the problem, in such a way that you can reuse this solution a million times over, without ever doing it the same way twice. Each pattern describes a problem which occurs over and over again in our environment and then describes the core of the solution to the problem, in such a way that you can reuse this solution a million times over, without ever doing it the same way twice.

9 9Ku-Yaw ChangThe Object-Oriented Paradigm Design Patterns Arose from Architecture and Anthropology Four essential items The name of the pattern The name of the pattern The purpose of the pattern, the problem it solves The purpose of the pattern, the problem it solves How we could accomplish this How we could accomplish this The constraints and forces we have to consider in order to accomplish it The constraints and forces we have to consider in order to accomplish it Alexander postulated Patterns can solve virtually every architectural problem that one will encounter Patterns can solve virtually every architectural problem that one will encounter Patterns could be used together to solve complex architectural problems Patterns could be used together to solve complex architectural problems

10 10Ku-Yaw ChangThe Object-Oriented Paradigm Outline Overview Design Patterns Arose from Architecture and Anthropology Moving from Architectural to Software Design Patterns Why Study Design Patterns? Other Advantages to Studying Design Patterns Summary

11 11Ku-Yaw ChangThe Object-Oriented Paradigm Moving from Architectural to Software Design Patterns In the early 1990s, some smart developers Happened upon Alexander’s work in patterns Happened upon Alexander’s work in patterns Wondered if what was true for architectural patterns would also be true for software design? Wondered if what was true for architectural patterns would also be true for software design? Were there problems in software that occur over and over again that could be solved somewhat the same manner? Was it possible to design software in terms of patterns, creating specific solutions based on these patterns only after the patterns had been identified? The answer to both of the above questions are “unequivocally yes.” The answer to both of the above questions are “unequivocally yes.”

12 12Ku-Yaw ChangThe Object-Oriented Paradigm Moving from Architectural to Software Design Patterns Early work on design patterns Design Patterns: Elements of Reusable Object- Oriented Software by GoF Design Patterns: Elements of Reusable Object- Oriented Software by GoF Identified the patterns ( not create the patterns ) Served the following purposes Served the following purposes It applied the idea of design patterns to software design. It described a structure within which to catalog and describe design patterns. It cataloged 23 such patterns. It postulated object-oriented strategies and approaches based on these design patterns.

13 13Ku-Yaw ChangThe Object-Oriented Paradigm Key Features of Patterns

14 14Ku-Yaw ChangThe Object-Oriented Paradigm Outline Overview Design Patterns Arose from Architecture and Anthropology Moving from Architectural to Software Design Patterns Why Study Design Patterns? Other Advantages to Studying Design Patterns Summary

15 15Ku-Yaw ChangThe Object-Oriented Paradigm Why Study Design Patterns? Reuse solutions Not have to reinvent solutions for commonly recurring problems Not have to reinvent solutions for commonly recurring problems Establish common terminology A common base of vocabulary A common base of vocabulary A common viewpoint of the problem A common viewpoint of the problem Give a higher-level perspective On the problem On the problem On the process of design and object orientation On the process of design and object orientation

16 16Ku-Yaw ChangThe Object-Oriented Paradigm Why Study Design Patterns? A conversation between two carpenters Carpenter 1: How do you think we should build these drawers? Carpenter 1: How do you think we should build these drawers? Carpenter 2: Well, I think we should make the joint by cutting straight down into the wood, and then cut back up 45 degrees, and the going straight back down, and then back up the other way 45 degree, and the going straight back down, and then … Carpenter 2: Well, I think we should make the joint by cutting straight down into the wood, and then cut back up 45 degrees, and the going straight back down, and then back up the other way 45 degree, and the going straight back down, and then … The details may confuse the solution.

17 17Ku-Yaw ChangThe Object-Oriented Paradigm Why Study Design Patterns?

18 18Ku-Yaw ChangThe Object-Oriented Paradigm Why Study Design Patterns? Carpenter 1: Should we use a dovetail joint or a miter joint? A miter joint A miter joint It is a simpler solution. It is lightweight. It is inconspicuous. A dovetail joint A dovetail joint It is a more complex solution. It is impervious to temperature and humidity. It is independent of the fastening system. It is a more aesthetically pleasing joint.

19 19Ku-Yaw ChangThe Object-Oriented Paradigm Why Study Design Patterns? Carpenter 1 Should we use a dovetail joint or a miter joint? Should we use a dovetail joint or a miter joint? The real question is The real question is Should we use a joint that is expensive to make but is both beautiful and durable, or should we just make a quick and dirty joint that will last at least as long until the check clears? Should we use a joint that is expensive to make but is both beautiful and durable, or should we just make a quick and dirty joint that will last at least as long until the check clears? Which is more efficient? Who would you rather work with? Patterns help raise the level of your thinking See the forest and the trees See the forest and the trees

20 20Ku-Yaw ChangThe Object-Oriented Paradigm Outline Overview Design Patterns Arose from Architecture and Anthropology Moving from Architectural to Software Design Patterns Why Study Design Patterns? Other Advantages to Studying Design Patterns Summary

21 21Ku-Yaw ChangThe Object-Oriented Paradigm Other Advantages to Studying Design Patterns Experiences from the Author Help both individual learning and team development Help both individual learning and team development Improve modifiability of code Improve modifiability of code Illustrate basic object-oriented principles Illustrate basic object-oriented principles Strategies from GoF Design to Interface Design to Interface Favor composition over inheritance Favor composition over inheritance Find what varies and encapsulate it Find what varies and encapsulate it

22 22Ku-Yaw ChangThe Object-Oriented Paradigm Outline Overview Design Patterns Arose from Architecture and Anthropology Moving from Architectural to Software Design Patterns Why Study Design Patterns? Other Advantages to Studying Design Patterns Summary

23 23Ku-Yaw ChangThe Object-Oriented Paradigm Summary Reasons for studying design patterns Reuse existing, high-quality solutions to commonly recurring problems. Reuse existing, high-quality solutions to commonly recurring problems. Establish common terminology to improve communications within teams. Establish common terminology to improve communications within teams. Shift the level of thinking to a higher perspective. Shift the level of thinking to a higher perspective. Decide whether I have the right design, not just one that works. Decide whether I have the right design, not just one that works.

24 24Ku-Yaw ChangThe Object-Oriented Paradigm Summary (cont.) Improve individual learning and team learning. Improve individual learning and team learning. Improve the modifiability of code. Improve the modifiability of code. Facilitate adoption of improved design alternatives, even when patterns are not used explicitly. Facilitate adoption of improved design alternatives, even when patterns are not used explicitly. Discover alternatives to large inheritance hierarchies. Discover alternatives to large inheritance hierarchies.

25 The End


Download ppt "Chapter Five An Introduction to Design Patterns Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information."

Similar presentations


Ads by Google