250 likes | 259 Views
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. Outline. Overview Design Patterns Arose from Architecture and Anthropology
E N D
Chapter FiveAn Introduction toDesign Patterns Ku-Yaw Chang canseco@mail.dyu.edu.tw Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University
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 An Introduction to Design Patterns
Overview • Design patterns • Cutting edge of the OO technology • Relationships • Master OO skills first, then learn design patterns • 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 • Many ideas are from • Christopher Alexander’s Timeless Way of Building An Introduction to Design Patterns
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 An Introduction to Design Patterns
Design Patterns Arose from Architecture and Anthropology • Christopher Alexander asked himself • Is quality objective? • What makes us know when an architectural design is good? • Alexander postulates • There is such an objective basis within architectural systems. • We can describe beauty through an objective basis that can be measured. An Introduction to Design Patterns
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 • Alexander asked • 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? • Alexander discovered • Good constructs had things in common with each other An Introduction to Design Patterns
Design Patterns Arose from Architecture and Anthropology • Two porches may • appear structurally different • solve the same (or similar) problem • be considered high quality An Introduction to Design Patterns
Design Patterns Arose from Architecture and Anthropology • Alexander narrowed his focus • Look at structures that solve similar problems • Discern similarities between designs that were high quality • 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. An Introduction to Design Patterns
Design Patterns Arose from Architecture and Anthropology • Four essential items • The name of the pattern • The purpose of the pattern, the problem it solves • How we could accomplish this • 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 could be used together to solve complex architectural problems An Introduction to Design Patterns
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 An Introduction to Design Patterns
Moving from Architectural to Software Design Patterns • In the early 1990s, some smart developers • Happened upon Alexander’s work in patterns • 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.” An Introduction to Design Patterns
Moving from Architectural to Software Design Patterns • Early work on design patterns • Design Patterns: Elements of Reusable Object-Oriented Software by GoF • Identified the patterns ( not create the patterns ) • 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. An Introduction to Design Patterns
Key Features of Patterns An Introduction to Design Patterns
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 An Introduction to Design Patterns
Why Study Design Patterns? • Reuse solutions • Not have to reinvent solutions for commonly recurring problems • Establish common terminology • A common base of vocabulary • A common viewpoint of the problem • Give a higher-level perspective • On the problem • On the process of design and object orientation An Introduction to Design Patterns
Why Study Design Patterns? • A conversation between two carpenters • 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 … • The details may confuse the solution. An Introduction to Design Patterns
Why Study Design Patterns? An Introduction to Design Patterns
Why Study Design Patterns? • Carpenter 1: Should we use a dovetail joint or a miter joint? • A miter joint • It is a simpler solution. • It is lightweight. • It is inconspicuous. • 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. An Introduction to Design Patterns
Why Study Design Patterns? • Carpenter 1 • Should we use a dovetail joint or a miter joint? 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? • Which is more efficient?Who would you rather work with? • Patterns help raise the level of your thinking • See the forest and the trees An Introduction to Design Patterns
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 An Introduction to Design Patterns
Other Advantages toStudying Design Patterns • Experiences from the Author • Help both individual learning and team development • Improve modifiability of code • Illustrate basic object-oriented principles • Strategies from GoF • Design to Interface • Favor composition over inheritance • Find what varies and encapsulate it An Introduction to Design Patterns
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 An Introduction to Design Patterns
Summary • Reasons for studying design patterns • Reuse existing, high-quality solutions to commonly recurring problems. • Establish common terminology to improve communications within teams. • Shift the level of thinking to a higher perspective. • Decide whether I have the right design, not just one that works. An Introduction to Design Patterns
Summary (cont.) • Improve individual learning and team learning. • Improve the modifiability of code. • Facilitate adoption of improved design alternatives, even when patterns are not used explicitly. • Discover alternatives to large inheritance hierarchies. An Introduction to Design Patterns