Docsity

Design Patterns: An Introduction, Exercises of Object Oriented Analysis and Design

Partial preview of the text

Download Design Patterns: An Introduction and more Exercises Object Oriented Analysis and Design in PDF only on Docsity!

1

An Introduction to Design Patterns

Douglas C. Schmidt

Vanderbilt University

www.dre.vanderbilt.edu/~schmidt/gof.ppt

[email protected]

Based on material produced by John Vlissides

Overview

Part I: Motivation & Concept

 the issue

 what design patterns are

 what they’re good for

 how we develop & categorize them

4

Part I: Motivation & Concept

OOD methods emphasize design notations

Fine for specification, documentation

But OOD is more than just drawing diagrams

Good draftsmen  good designers

Good OO designers rely on lots of experience

At least as important as syntax

Most powerful reuse is design reuse Match problem to design experience

Part I: Motivation & Concept (cont’d)

Recurring Design Structures

OO systems exhibit recurring structures that

promote

 abstraction  flexibility  modularity  elegance

Therein lies valuable design knowledge

Problem:

capturing, communicating, & applying this

knowledge

Part I: Motivation & Concept (cont’d)

Four Basic Parts

1. Name
2. Problem (including “forces”)
3. Solution
4. Consequences & trade-offs of application

Language- & implementation-independent A “micro-architecture” Adjunct to existing methodologies (RUP, Fusion, SCRUM, etc.)

Part I: Motivation & Concept (cont’d)

Example: OBSERVER

Part I: Motivation & Concept (cont’d)

Design Space for GoF Patterns

Scope : domain over which a pattern applies Purpose : reflects what a pattern does

Part I: Motivation & Concept (cont’d)

Design Pattern Template (1st half)

NAME scope purpose

Intent short description of the pattern & its purpose Also Known As Any aliases this pattern is known by Motivation motivating scenario demonstrating pattern’s use Applicability circumstances in which pattern applies Structure graphical representation of the pattern using modified UML notation Participants participating classes and/or objects & their responsibilities

Part I: Motivation & Concept (cont’d)

Modified UML/OMT Notation

Motivation & Concept (cont’d)

OBSERVER object behavioral

Intent

define a one-to-many dependency between objects so that when one object changes state, all dependents are notified & updated

Applicability

 an abstraction has two aspects, one dependent on the other  a change to one object requires changing untold others  an object should notify unknown other objects

Structure

16

Motivation & Concept (cont’d)

OBSERVER (cont’d) object behavioral

Consequences

  • modularity: subject & observers may vary independently
  • extensibility: can define & add any number of observers
  • customizability: different observers offer different views of subject
  • unexpected updates: observers don’t know about each other
  • update overhead: might need hints or filtering

Implementation  subject-observer mapping  dangling references  update protocols: the push & pull models  registering modifications of interest explicitly

Known Uses  Smalltalk Model-View-Controller (MVC)  InterViews (Subjects & Views, Observer/Observable)  Andrew (Data Objects & Views)  Pub/sub middleware (e.g., CORBA Notification Service, Java Messaging Service)  Mailing lists

Part I: Motivation & Concept (cont’d)

Benefits of Patterns

  • Design reuse
  • Uniform design vocabulary
  • Enhance understanding, restructuring, &

team communication

  • Basis for automation
  • Transcends language-centric biases/myopia
  • Abstracts away from many unimportant

details

19

Part II: Application: Document

Editor (Lexi)

  1. Document structure
  2. Formatting
  3. Embellishment
  4. Multiple look & feels
  5. Multiple window systems
  6. User operations
  7. Spelling checking & hyphenation

7 Design Problems

Note that none of these patterns are restricted to document editors…

Document Structure

Goals:

 present document’s visual aspects  drawing, hit detection, alignment  support physical structure (e.g., lines, columns)

Constraints/forces:

 treat text & graphics uniformly  no distinction between one & many