This preview shows page 1-2-3-19-20-38-39-40 out of 40 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Design PatternsPrinciples of Software System ConstructionPrinciples of Software System ConstructionProf. Jonathan AldrichFall 2011A First Pattern: Composite (Structural)• Applicability– You want to represent part-whole hierarchies of objects– You want to be able to ignore the difference between compositions of objects and individual objects• Consequences–Makes the client simple, since it can –Makes the client simple, since it can treat objects and composites uniformly– Makes it easy to add new kinds of components– Can make the design overly general• Operations may not make sense on every class• Composites may contain only certain componentsDesign PatternsPrinciples of Software System Construction © 2011 Jonathan Aldrich2Design Patterns• "Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice”twice”– Christopher Alexander• Every Composite has its own domain-specific interface– But they share a common problem and solutionDesign PatternsPrinciples of Software System Construction © 2011 Jonathan Aldrich3History• Christopher Alexander, The Timeless Way of Building (and other books– Proposes patterns as a way of capturing design knowledge in architecture– Each pattern represents a tried-and-true solution to a design problem– Typically an engineering compromise that resolves conflicting forces in an advantageous wayan advantageous way• Composite: you have a part-whole relationship, but want to treat individual objects and object compositions uniformlyDesign PatternsPrinciples of Software System Construction © 2011 Jonathan Aldrich4Patterns in Physical Architecture• When a room has a window with a view, the window becomes a focal point: people are attracted to the window and want to look through it. The furniture in the room creates a second focal point: everyone is attracted toward whatever point the furniture aims them at (usually the center of the room or a TV). This makes people feel uncomfortable. They want to look out the window, and toward the other focus at the same time. out the window, and toward the other focus at the same time. If you rearrange the furniture, so that its focal point becomes the window, then everyone will suddenly notice that the room is much more “comfortable”. – Leonard Budney, Amazon.com review of The Timeless Way of BuildingDesign PatternsPrinciples of Software System Construction © 2011 Jonathan Aldrich5Benefits of Patterns• Shared language of design– Increases communication bandwidth– Decreases misunderstandings•Learn from experience•Learn from experience– Becoming a good designer is hard• Understanding good designs is a first step– Tested solutions to common problems• Where is the solution applicable?• What are the tradeoffs?Design PatternsPrinciples of Software System Construction © 2011 Jonathan Aldrich6Illustration [Shalloway and Trott]• 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 then going straight back down, and then back up the other way 45 degrees, and then going straight down, and degrees, and then going straight back down, and then back up the other way 45 degrees, and then going straight down, and repeating…Design PatternsPrinciples of Software System Construction © 2011 Jonathan Aldrich7Illustration [Shalloway and Trott]• 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 then going straight back down, and then back up the other way 45 degrees, and then going straight down, and degrees, and then going straight back down, and then back up the other way 45 degrees, and then going straight down, and repeating…• SE example: “I wrote this if statement to handle … followed by a while loop … with a break statement so that…”Design PatternsPrinciples of Software System Construction © 2011 Jonathan Aldrich8A Better Way• Carpenter 1: Should we use a dovetail joint or a miter joint?• Subtext:– miter joint: cheap, invisible, breaks easily– dovetail joint: expensive, beautiful, durable• Shared terminology and knowledge of consequencesraises level of abstraction– CS: Should we use a Composite?– Subtext• Is there a part-whole relationship here?• Might there be advantages to treating compositions and individuals uniformly?Design PatternsPrinciples of Software System Construction © 2011 Jonathan Aldrich9Elements of a Pattern• Name– Important because it becomes part of a design vocabulary– Raises level of communication• Problem– When the pattern is applicable• Solution–Design elements and their relationships–Design elements and their relationships– Abstract: must be specialized• Consequences– Tradeoffs of applying the pattern• Each pattern has costs as well as benefits• Issues include flexibility, extensibility, etc.• There may be variations in the pattern with different consequencesDesign PatternsPrinciples of Software System Construction © 2011 Jonathan Aldrich10History: Design Patterns Book• Brought Design Patterns into the mainstream• Authors known as the Gang of Four (GoF)• Focuses on descriptions of communicating objects and classes that are customized to solve a Design PatternsPrinciples of Software System Construction © 2011 Jonathan Aldrich11that are customized to solve a general design problem in a particular context• Great as a reference text• Uses C++, SmalltalkA More Recent Patterns Text• Uses Java– The GoF text was written before Java went mainstream• Good pedagogically–General design informationDesign PatternsPrinciples of Software System Construction © 2011 Jonathan Aldrich12–General design information– Lots of examples and explanation– GoF is really more a reference text• Read it!Fundamental OO Design Principles• Patterns emerge from fundamental principles applied to recurring problems– Design to interfaces– Favor composition over inheritance– Find what varies and encapsulate itDesign PatternsPrinciples of Software System Construction © 2011 Jonathan


View Full Document

CMU CS 15214 - Design Patterns

Download Design Patterns
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Design Patterns and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Design Patterns 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?