(c) 2010 university of california, irvine – andré van der hoek1june 29, 2015 – 08:55:05...
Post on 21-Dec-2015
216 views
TRANSCRIPT
(c) 2010 University of California, Irvine – André van der Hoek 1April 18, 2023 – 22:10:54
Informatics 122Software Design II
Informatics 122Software Design II
Lecture 8André van der Hoek
Duplication of course material for any commercial purpose without the explicit written permission of the professor is prohibited.
(c) 2010 University of California, Irvine – André van der Hoek 2April 18, 2023 – 22:10:54
Today’s LectureToday’s Lecture
Design patterns
Assignment 4
(c) 2010 University of California, Irvine – André van der Hoek 3April 18, 2023 – 22:10:54
Fundamental PrinciplesFundamental Principles
Apply rigor Separate concerns
– modularize– abstract
Anticipate change Generalize Work incrementally
(c) 2010 University of California, Irvine – André van der Hoek 4April 18, 2023 – 22:10:54
A Checklist on Overall DesignA Checklist on Overall Design
Strive for grouping related functionality (high cohesion) Strive for ungrouping semi-related functionality (high
cohesion) Strive for reducing interdependency (low coupling)
(c) 2010 University of California, Irvine – André van der Hoek 5April 18, 2023 – 22:10:54
A Checklist on Class DesignA Checklist on Class Design
Cohesion Completeness Convenience Clarity Consistency
(c) 2010 University of California, Irvine – André van der Hoek 6April 18, 2023 – 22:10:54
A Checklist on Principles and StrategiesA Checklist on Principles and Strategies
Principles– keep it simple, stupid! (KISS)– information hiding– acyclic dependencies– …
Strategies– program to the interface– refactor– apply software patterns– use aspects– …
(c) 2010 University of California, Irvine – André van der Hoek 7April 18, 2023 – 22:10:54
A Checklist on Principles and StrategiesA Checklist on Principles and Strategies
Principles– keep it simple, stupid! (KISS)– information hiding– acyclic dependencies– …
Strategies– program to the interface– refactor– apply software patterns– use aspects– …
(c) 2010 University of California, Irvine – André van der Hoek 8April 18, 2023 – 22:10:54
Design PatternsDesign 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” [Alexander, Ishikawa, Silverstein 1977]
Pattern– name– problem– solution– consequences
(c) 2010 University of California, Irvine – André van der Hoek 9April 18, 2023 – 22:10:54
Software Design PatternsSoftware Design Patterns
“Descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context” [Gamma, Helm, Johnson, Vlissides 1995]
Pattern– name and classification– intent– also known as– motivation– applicability– structure– participants– collaborations– consequences– implementation– sample code– known uses– related patterns
(c) 2010 University of California, Irvine – André van der Hoek 10April 18, 2023 – 22:10:54
Patterns Are Designed to Avoid RedesignPatterns Are Designed to Avoid Redesign
Creating an object by specifying a class explicitly Dependence on specific operations Dependence on hardware and software platform Dependence on object representations or
implementations Algorithmic dependencies Tight coupling Extending functionality by subclassing Inability to alter classes conveniently
(c) 2010 University of California, Irvine – André van der Hoek 11April 18, 2023 – 22:10:54
Patterns Apply Two Design PrinciplesPatterns Apply Two Design Principles
Program to an interface, not an implementation– interface should be separately defined, using abstract
classes Favor object composition over inheritance
(c) 2010 University of California, Irvine – André van der Hoek 12April 18, 2023 – 22:10:54
Original Catalogue of PatternsOriginal Catalogue of Patterns
Purpose
Creational Structural Behavioral
Scope
Class Abstract Method Adapter (class) InterpreterTemplate Method
Object
Abstract FactoryBuilderPrototypeSingleton
Adapter (object)BridgeCompositeDecoratorFaçadeFlyweightProxy
Chain of ResponsibilityCommandIteratorMediatorMementoObserverStateStrategyVisitor
(c) 2010 University of California, Irvine – André van der Hoek 13April 18, 2023 – 22:10:54
Abstract Method (Creational, Class)Abstract Method (Creational, Class)
(c) 2010 University of California, Irvine – André van der Hoek 14April 18, 2023 – 22:10:55
Abstract Factory (Creational, Object)Abstract Factory (Creational, Object)
(c) 2010 University of California, Irvine – André van der Hoek 15April 18, 2023 – 22:10:55
Builder (Creational, Object)Builder (Creational, Object)
(c) 2010 University of California, Irvine – André van der Hoek 16April 18, 2023 – 22:10:55
Adaptor (Structural, Object)Adaptor (Structural, Object)
(c) 2010 University of California, Irvine – André van der Hoek 17April 18, 2023 – 22:10:55
Composite (Structural, Object)Composite (Structural, Object)
(c) 2010 University of California, Irvine – André van der Hoek 18April 18, 2023 – 22:10:55
Decorator (Structural, Object)Decorator (Structural, Object)
(c) 2010 University of California, Irvine – André van der Hoek 19April 18, 2023 – 22:10:55
Proxy (Structural, Object)Proxy (Structural, Object)
(c) 2010 University of California, Irvine – André van der Hoek 20April 18, 2023 – 22:10:55
Command (Behavioral, Object)Command (Behavioral, Object)
(c) 2010 University of California, Irvine – André van der Hoek 21April 18, 2023 – 22:10:55
Observer (Behavioral, Object)Observer (Behavioral, Object)
(c) 2010 University of California, Irvine – André van der Hoek 22April 18, 2023 – 22:10:55
State (Behavioral, Object)State (Behavioral, Object)
(c) 2010 University of California, Irvine – André van der Hoek 23April 18, 2023 – 22:10:55
Visitor (Behavioral, Object)Visitor (Behavioral, Object)
(c) 2010 University of California, Irvine – André van der Hoek 24April 18, 2023 – 22:10:55
More…More…
Patterns– http://en.wikipedia.org/wiki/Software_pattern– http://c2.com/ppr/
Interaction design patterns– http://en.wikipedia.org/wiki/Interaction_design_pattern
Anti-Patterns– http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-
patterns
Refactoring– http://en.wikipedia.org/wiki/Refactoring
And numerous, numerous, numerous books
© 2010 University of California, Irvine – André van der Hoek 25February 8, 2010 – 21:49:30
Assignment 4 – Design Patterns
Improve the design of Calico by replacing existing structures in the UML model with appropriate patterns– start with any of the designs available to your group
You should apply at least 7 different design patterns– at least three not discussed in class
Each use of a pattern should be carefully motivated in a brief accompanying document
© 2010 University of California, Irvine – André van der Hoek 26February 8, 2010 – 21:49:30
Assignment 4 – Design Patterns
Each group must turn in:– the original UML diagram from which you started– a new UML diagram, with each pattern precisely highlighted as
to where it resides in the UML diagram– a document describing
the motivation for each pattern the impact the application of the pattern has on the original design
(i.e., how far reaching is the change to incorporate the pattern?)– graded on usefulness of the pattern, diversity of patterns,
rationale, and level of design understanding
Each person also needs to submit a team evaluation (new forms available on class webpage)
Printed copy due Tuesday, February 16th at the beginning of class
© 2010 University of California, Irvine – André van der Hoek 27February 8, 2010 – 21:49:30
Further Tips
Read the book
Discuss the patterns with each other
Imagine possible changes against which you would like to insulate
Try different parts of the code
Use the UML