Top Banner
(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.
24

(c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

Dec 19, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

(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.

Page 2: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

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

Today’s LectureToday’s Lecture

Design patterns

Page 3: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

(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

Page 4: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

(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)

Page 5: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

(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

Page 6: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

(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– …

Page 7: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

(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– …

Page 8: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

(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

Page 9: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

(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

Page 10: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

(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

Page 11: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

(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

Page 12: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

(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

Page 13: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

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

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

Page 14: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

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

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

Page 15: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

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

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

Page 16: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

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

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

Page 17: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

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

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

Page 18: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

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

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

Page 19: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

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

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

Page 20: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

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

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

Page 21: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

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

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

Page 22: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

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

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

Page 23: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

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

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

Page 24: (c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.

(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