(c) 2009 university of california, irvine – andré van der hoek1june 13, 2015 – 21:42:16...

24
(c) 2009 University of California, Irvine – André van der Hoek 1 March 27, 2022 – 03:32:05 Informatics 122 Software Design II Lecture 8 André van der Hoek Duplication of course material for any commercial purpose without the explicit written permission of the professor is prohibited.

Post on 19-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

(c) 2009 University of California, Irvine – André van der Hoek 1April 18, 2023 – 20:52:20

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) 2009 University of California, Irvine – André van der Hoek 2April 18, 2023 – 20:52:20

Today’s LectureToday’s Lecture

Design patterns

(c) 2009 University of California, Irvine – André van der Hoek 3April 18, 2023 – 20:52:20

Fundamental PrinciplesFundamental Principles

Apply rigor Separate concerns

– modularize– abstract

Anticipate change Generalize Work incrementally

(c) 2009 University of California, Irvine – André van der Hoek 4April 18, 2023 – 20:52:20

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) 2009 University of California, Irvine – André van der Hoek 5April 18, 2023 – 20:52:20

A Checklist on Class DesignA Checklist on Class Design

Cohesion Completeness Convenience Clarity Consistency

(c) 2009 University of California, Irvine – André van der Hoek 6April 18, 2023 – 20:52:20

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) 2009 University of California, Irvine – André van der Hoek 7April 18, 2023 – 20:52:20

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) 2009 University of California, Irvine – André van der Hoek 8April 18, 2023 – 20:52:20

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) 2009 University of California, Irvine – André van der Hoek 9April 18, 2023 – 20:52:20

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) 2009 University of California, Irvine – André van der Hoek 10April 18, 2023 – 20:52:20

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) 2009 University of California, Irvine – André van der Hoek 11April 18, 2023 – 20:52:20

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) 2009 University of California, Irvine – André van der Hoek 12April 18, 2023 – 20:52:20

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) 2009 University of California, Irvine – André van der Hoek 13April 18, 2023 – 20:52:20

Abstract Method (Creational, Class)Abstract Method (Creational, Class)

(c) 2009 University of California, Irvine – André van der Hoek 14April 18, 2023 – 20:52:21

Abstract Factory (Creational, Object)Abstract Factory (Creational, Object)

(c) 2009 University of California, Irvine – André van der Hoek 15April 18, 2023 – 20:52:21

Builder (Creational, Object)Builder (Creational, Object)

(c) 2009 University of California, Irvine – André van der Hoek 16April 18, 2023 – 20:52:21

Adaptor (Structural, Object)Adaptor (Structural, Object)

(c) 2009 University of California, Irvine – André van der Hoek 17April 18, 2023 – 20:52:21

Composite (Structural, Object)Composite (Structural, Object)

(c) 2009 University of California, Irvine – André van der Hoek 18April 18, 2023 – 20:52:21

Decorator (Structural, Object)Decorator (Structural, Object)

(c) 2009 University of California, Irvine – André van der Hoek 19April 18, 2023 – 20:52:21

Proxy (Structural, Object)Proxy (Structural, Object)

(c) 2009 University of California, Irvine – André van der Hoek 20April 18, 2023 – 20:52:21

Command (Behavioral, Object)Command (Behavioral, Object)

(c) 2009 University of California, Irvine – André van der Hoek 21April 18, 2023 – 20:52:21

Observer (Behavioral, Object)Observer (Behavioral, Object)

(c) 2009 University of California, Irvine – André van der Hoek 22April 18, 2023 – 20:52:21

State (Behavioral, Object)State (Behavioral, Object)

(c) 2009 University of California, Irvine – André van der Hoek 23April 18, 2023 – 20:52:21

Visitor (Behavioral, Object)Visitor (Behavioral, Object)

(c) 2009 University of California, Irvine – André van der Hoek 24April 18, 2023 – 20:52:21

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