SlideShare une entreprise Scribd logo
1  sur  129
Background-Origins of Design Patterns
 Building Architecture pattern
 Christopher Alexander, architect
 A Pattern Language---Towns, Buildings, Construction
(1977)
 Timeless Way of Building (1979)
 “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.”
---Christopher Alexander, Sara Ishikawa, Murray
Silverstein, Max Jacobson, Ingrid Fiksdahl-King, Shlomo
Angel, “A Pattern Language: Towns/Buildings/
Construction”, Oxford University Press, New York, 1977
 …
Background
 In 1987, Kent Beck and Ward Cunningham
began experimenting with the idea of
applying patterns to programming and
presented their results at the OOPSLA
conference that year.
----Beck, Kent; Ward Cunningham (September 1987). "Using Pattern
Languages for Object-Oriented Program". OOPSLA '87 workshop on
Specification and Design for Object-Oriented Programming. OOPSLA
'87. http://c2.com/doc/oopsla87.html
Background
 In software engineering
 Search for recurring successful designs –
emergent designs from practice (via trial and
error)
 Supporting higher levels of reuse (i.e., reuse of
designs) is quite challenging
What is a Design Pattern?
 In software engineering, a design pattern is a general
reusable solution to a commonly occurring problem in
software design. A design pattern is not a finished design
that can be transformed directly into code. It is a description
or template for how to solve a problem that can be used in
many different situations. Object-oriented design patterns
typically show relationships and interactions between
classes or objects, without specifying the final application
classes or objects that are involved.
---
http://en.wikipedia.org/wiki/Design_pattern_(computer_s
cience)
What Is a Design Pattern?
 A design pattern
 Is a common solution to a recurring problem
in design
 Abstracts a recurring design structure
 Comprises class and/or object
 Dependencies
 Structures
 Interactions
 Conventions
 Names & specifies the design structure
explicitly
 Distils design experience
Re-use Code VS. Design
 Code re-use
 Don’t reinvent the wheel
 Requires
clean, elegant, understandable, general, stable
code
 leverage previous work
 Design re-use
 Don’t reinvent the wheel
 Requires a precise understanding of
common, recurring designs
 leverage previous work
Patterns vs “Design”
 Patterns are design
 But: patterns transcend the “identify classes and
associations” approach to design
 Instead: learn to recognize patterns in the problem
space and translate to the solution
 Patterns can capture OO design principles
within a specific domain
 Patterns provide structure to “design”
Design Patterns VS. Architecture Patterns
 Design patterns reside in the domain of
modules and interconnections.
 At a higher level there are Architectural
patterns that are larger in scope, usually
describing an overall pattern followed by an
entire system.
Design Patterns VS. Architecture Patterns
 Design Patterns represent a lower level of system
structure than “software architecture” (cf: seven
levels of A)
 Patterns can be applied to architecture:
 Mowbray and Malveau
 Buschmann et al
 Schmidt et al
 Architectural patterns tend to be focussed on
middleware. They are good at capturing:
 Concurrency
 Distribution
 Synchronization
Why design patterns in SA?
 If you’re a software engineer, you should
know about them anyway.
 There are many architectural patterns
published, and the Design Patterns is a
prerequisite to understanding these:
 Mowbray and Malveau – CORBA Design Patterns
 Schmidt et al – Pattern-Oriented Software
Architecture
 Design Patterns help you break out of first-
generation OO thought patterns
The seven layers of architecture*
Global architecture
Enterprise architecture
System architecture
Application architecture
Macro-architecture
Micro-architecture
Objects
ORB
OO architecture
Frameworks
Subsystem
Design patterns
OO programming
Design Patterns VS. Software Patterns
 Not all software patterns are design patterns.
 For instance, algorithms solve computational
problems rather than software design problems.
 Design problem
 Programming problem
 Computational problem
What Makes it a Pattern?
 A Pattern must:
 Solve a problem and be useful
 Have a context and can describe where the solution
can be used
 Recur in relevant situations
 Provide sufficient understanding to tailor the solution
 Have a name and be referenced consistently
Description of a Design Pattern
 Description of communicating objects and classes that
are customized to solve a general design problem in a
particular context.
 Language- & implementation-independent
 A “micro-architecture”
 Adjunct to existing methodologies (RUP, Fusion,
SCRUM, etc.)
Description of a Design Pattern
 Graphical notation is generally not sufficient
 In order to reuse design decisions the
alternatives and trade-offs that led to the
decisions are critical knowledge
 Concrete examples are also important
 The history of the why, when, and how set the
stage for the context of usage
Description of a Design Pattern
 Describe a recurring design structure
 Defines a common vocabulary
 Abstracts from concrete designs
 Identifies classes, collaborations, and responsibilities
 Describes applicability, trade-offs, and
consequences
 Formats of pattern writers vary, but a pattern description
usually has at least these four things.
 pattern name
 problem
 solution
 Consequences
Pattern Name
 A handle used to describe:
 a design problem
 its solutions
 its consequences
 Increases design vocabulary
 Makes it possible to design at a higher level of
abstraction
 Enhances communication
 “The Hardest part of programming is coming up
with good variable [function, and type] names.”
Problem
 Describes when to apply the pattern
 Explains the problem and its context
 May describe specific design problems and/or
object structures
 May contain a list of preconditions that must be
met before it makes sense to apply the pattern
Solution
 Describes the elements that make up the
 design
 relationships
 responsibilities
 collaborations
 Does not describe specific concrete
implementation
 Abstract description of design problems and
how the pattern solves it
Consequences
 Results and trade-offs of applying the pattern
 Critical for:
 evaluating design alternatives
 understanding costs
 understanding benefits of applying the pattern
 Includes the impacts of a pattern on a system’s:
 flexibility
 extensibility
 portability
Design Pattern Template
 Pattern Name and Classification:
 A descriptive and unique name that helps in identifying and referring to the
pattern.
 Intent:
 A description of the goal behind the pattern and the reason for using it.
 Also Known As:
 Other names for the pattern.
 Motivation (Forces):
 A scenario consisting of a problem and a context in which this pattern can
be used.
 Applicability:
 Situations in which this pattern is usable; the context for the pattern.
 Structure:
 A graphical representation of the pattern. Class diagrams and Interaction
diagrams may be used for this purpose.
 Participants:
 A listing of the classes and objects used in the pattern and their roles in the
design. 22
Design Pattern Template
 Collaboration:
 A description of how classes and objects used in the pattern interact
with each other.
 Consequences:
 A description of the results, side effects, and trade offs caused by
using the pattern.
 Implementation:
 A description of an implementation of the pattern; the solution part of
the pattern.
 Sample Code:
 An illustration of how the pattern can be used in a programming
language.
 Known Uses:
 Examples of real usages of the pattern.
 Related Patterns:
 Other patterns that have some relationship with the pattern;
discussion of the differences between the pattern and similar
patterns.
Goals of Design Patterns
 Codify good design
 Distil and disseminate experience
 Aid to novices and experts alike
 Abstract how to think about design
 Give design structures explicit names
 Common vocabulary
 Reduced complexity
 Greater expressiveness
 Capture and preserve design information
 Articulate design decisions succinctly
 Improve documentation
 Facilitate restructuring/refactoring
 Patterns are interrelated
 Additional flexibility
Goals of Design Patterns
 Design patterns can speed up the development
process by providing tested, proven development
paradigms.
 Effective software design requires considering
issues that may not become visible until later in the
implementation.
 Reusing design patterns helps to prevent subtle
issues that can cause major problems, and it also
improves code readability for coders and architects
who are familiar with the patterns.
Design Patterns
Why Design Patterns?
 Designing OO software is hard
 Designing reusable OO software – harder
 Experienced OO designers make good design
 New designers tend to fall back on non-OO
techniques used before
 Experienced designers know something – what
is it?
Why Design Patterns?
 Expert designers know not to solve every
problem from first principles.
 They reuse solutions.
 These patterns make OO designs more flexible,
elegant, and ultimately reusable.
Two Major Principles of Object-Oriented Design
 Program to an interface, not an implementation.
 Favor object compositions over class
inheritance.
29
OO Desgin
 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
30
Recurring OO Design Structures
 OO systems exhibit recurring structures that
promote
 abstraction
 flexibility
 modularity
 elegance
 find pertinent objects and factor them into classes at
the right granularity.
 define class interfaces and inheritance hierarchies
 Establish key relationship among classes.
OO Design is hard
 The design should be specific to the problem at
hand, but also general enough to address
future problems and requirements.
 Therein lies valuable design knowledge, the
problem is
 Capturing,
 Communicating,
 applying this knowledge
Expert designers use patterns
 When they find a good solution, they use it
again and again.
 The design patterns solve specific design
problems and make OO designs more
flexible, elegant, and ultimately reusable.
 A designer who is familiar with patterns can
apply them immediately to design problems.
A design pattern can …
 Make it easier to reuse successful designs and
architectures.
 Help you choose good design: make system
reusable.
 Improve the documentation and maintenance.
Why Study Design Patterns?
 Can reuse solutions.
 Gives us a head start
 Avoids the unanticipated things later
 No need to reinvent the wheel
 Establish common terminology
 Design patterns provide a common point of reference
 Easier to say, “We need some Strategies here.”
 Provide a higher level prospective.
 Frees us from dealing with the details too early.
State of the Art
 Notable Books:
 Gamma, Erich; Richard Helm, Ralph Johnson, and John Vlissides
(1995). Design Patterns: Elements of Reusable Object-Oriented
Software. Addison-Wesley. ISBN 0-201-63361-2.
 Schmidt, Douglas C.; Michael Stal, Hans Rohnert, Frank Buschmann
(2000). Pattern-Oriented Software Architecture, Volume 2: Patterns
for Concurrent and Networked Objects. John Wiley & Sons. ISBN 0-
471-60695-2.
 Fowler, Martin (2002). Patterns of Enterprise Application
Architecture. Addison-Wesley. ISBN 978-0321127426.
 Hohpe, Gregor; Bobby Woolf (2003). Enterprise Integration Patterns:
Designing, Building, and Deploying Messaging Solutions. Addison-
Wesley. ISBN 0-321-20068-3.
“Gang of Four” (GoF) Book
Design Patterns: Elements of
Reusable Object-Oriented
Software, Addison-Wesley
Publishing Company, 1995
This book solidified thinking about
patterns and became the seminal
Design Patterns text
“Gang of Four” (GoF)
 Dr. Erich Gamma, then Software
Engineer, Taligent, Inc.; now at Object Technology
International as the technical director of the Zurich lab
in Switzerland.
 Dr. Richard Helm, then Senior Technology
Consultant, DMR Group; now at the Boston Consulting
Group.
 Dr. Ralph Johnson, then and now at University of
Illinois, Computer Science Department; now a
Research Associate Professor.
 Dr. John Vlissides, then a researcher at IBM Thomas J.
Watson Research Center.
Patterns
 This book defined 23 patterns, classified into three
categories.
 Creational patterns, which deal with the process of object
creation.
 Structural patterns, which deal primarily with the static
composition and structure of classes and objects.
 Behavioral patterns, which deal primarily with dynamic interaction
among classes and objects.
 Many other patterns have been introduced by others.
 For example, the book Data Access Patterns by Clifton Nock
introduces 4 decoupling patterns, 5 resource patterns, 5 I/O
patterns, 7 cache patterns, and 4 concurrency patterns.
 Hundreds of patterns have been documented since; other
examples include telecommunications patterns, pedagogical
patterns, analysis patterns, and indexing patterns.
What’s in this book
 Designs that have been applied more than
once in different systems.
 Although the patterns are not new, they are
arranged in a new and accessible way.
 Three categories:
 Creational Patterns
 Structural Patterns
 Behavioral Patterns
What’s not in this book
 About concurrency or distributed programming
or real-time programming.
 application domain-specific patterns.
 patterns about user interfaces
 device drivers
 OO databases.
 But an expert should know the above.
Types of Patterns
 Creational patterns:
 Deal with initializing and configuring classes and
objects
 Structural patterns:
 Deal with decoupling interface and implementation
of classes and objects
 Composition of classes or objects
 Behavioral patterns:
 Deal with dynamic interactions among societies of
classes and objects
 How they distribute responsibility
Classification of GoF Design Pattern
Creational Structural Behavioral
Factory Method
Abstract Factory
Builder
Prototype
Singleton
Adapter
Bridge
Composite
Decorator
Flyweight
Facade
Proxy
Interpreter
Template Method
Chain of
Responsibility
Command
Iterator
Mediator
Memento
Observer
State
Strategy
Visitor
Alternative Classification (Reverse engineering)
Intent
language-provided
patterns
structure-driven
patterns
behavior-driven patterns domain-specific
patterns
generic concepts
Prototype
Iterator
Bridge
Composite
Adapter
Facade
Proxy
Template Method
Visitor
Singleton
Abstract Factory
Factory Method
Flyweight
Chain of Responsibility
Decorator
Strategy
State
Observer
Mediator
Command
Interpreter
Memento
Builder
Creational Patterns
 Abstract Factory:
 Factory for building related objects
 Builder:
 Factory for building complex objects incrementally
 Factory Method:
 Method in a derived class creates associates
 Prototype:
 Factory for cloning new instances from a prototype
 Singleton:
 Factory for a singular (sole) instance
Structural Patterns
 Adapter:
 Translator adapts a server interface for a client
 Bridge:
 Abstraction for binding one of many implementations
 Composite:
 Structure for building recursive aggregations
 Decorator:
 Decorator extends an object transparently
 Facade:
 Simplifies the interface for a subsystem
 Flyweight:
 Many fine-grained objects shared efficiently.
 Proxy:
 One object approximates another
Behavioral Patterns
 Chain of Responsibility:
 Request delegated to the responsible service provider
 Command:
 Request is first-class object
 Iterator:
 Aggregate elements are accessed sequentially
 Interpreter:
 Language interpreter for a small grammar
 Mediator:
 Coordinates interactions between its associates
 Memento:
 Snapshot captures and restores object states privately
Behavioral Patterns (cont.)
 Observer:
 Dependents update automatically when subject changes
 State:
 Object whose behavior depends on its state
 Strategy:
 Abstraction for selecting one of many algorithms
 Template Method:
 Algorithm with some steps supplied by a derived class
 Visitor:
 Operations applied to elements of a heterogeneous object
structure
Organization of Design Patterns
 Two criterion are used to classify patterns:
 Purpose
 creational,
 structural,
 behavioral
 Scope
 Class
 Object
50
Design Space for GoF Patterns
Scope: domain over which a pattern applies
Purpose: reflects what a pattern does
Categorization Terms
 Scope is the domain over which a pattern
applies
 Class Scope: relationships between base classes
and their subclasses (static semantics)
 Object Scope: relationships between peer objects
 Some patterns apply to both scopes.
Class::Creational
 Abstracts how objects are instantiated
 Hides specifics of the creation process
 May want to delay specifying a class name
explicitly when instantiating an object
 Just want a specific protocol
Example
 Use Factory Method to instantiate members in base
classes with objects created by subclasses
 Abstract Application class: create application-specific
documents conforming to a particular Document type
 Application instantiates these Document objects by
calling the factory method DoMakeDocument
 Method is overridden in classes derived from
Application
 Subclass DrawApplication overrides DoMakeDocument
to return a DrawDocument object
Class:: Structural
 Use inheritance to compose protocols or code
 Example:
 Adapter Pattern: makes one interface (Adaptee’s)
conform to another
 Gives a uniform abstraction of different interfaces
 Class Adapter inherits privately from an Adaptee
class
 Adapter then expresses its interface in terms of the
Adaptee’s.
Class:: Behavioral
 Captures how classes cooperate with their
subclasses to satisfy semantics.
Example:
 Template Method: defines algorithms step by
step.
 Each step can invoke an abstract method (that
must be defined by the subclass) or a base
method.
 Subclass must implement specific behavior to
provide required services
Object Scope
 Object Patterns all apply various forms of non-
recursive object composition.
 Object Composition: most powerful form of
reuse
 Reuse of a collection of objects is better
achieved through variations of their composition,
rather than through sub classing.
Object:: Creational
 Abstracts how sets of objects are created
Example:
 Abstract Factory: create “product” objects through generic
interface
 Subclasses may manufacture specialized versions or compositions of
objects as allowed by this generic interface
 User Interface Toolkit: 2 types of scroll bars (Motif and Open Look)
 Don’t want to hard-code specific one; an environment variable decides
 Class Kit:
 Encapsulates scroll bar creation (and other UI entities);
 An abstract factory that abstracts the specific type of scroll bar to
instantiate
 Subclasses of Kit refine operations in the protocol to return specialized
types of scroll bars.
 Subclasses MotifKit and OpenLookKit each have scroll bar operation.
Object:: Structural
 Describe ways to assemble objects to realize
new functionality
 Added flexibility inherent in object composition due
to ability to change composition at run-time
 not possible with static class composition
 Example:
 Proxy: acts as convenient surrogate or placeholder
for another object.
 Remote Proxy: local representative for object in a different
address space
 Virtual Proxy: represent large object that should be loaded
on demand
 Protected Proxy: protect access to the original object
Object:: Behavioral
 Describes how a group of peer objects cooperate to perform a task
that can be carried out by itself.
Example:
 Strategy Pattern: objectifies an algorithm
 Text Composition Object: support different line breaking algorithms
 Don’t want to hard-code all algs into text composition class/subclasses
 Objectify different algs and provide them as Compositor subclasses
(contains criteria for line breaking strategies)
 Interface for Compositors defined by Abstract Compositor Class
 Derived classes provide different layout strategies (simple line breaks,
left/right justification, etc.)
 Instances of Compositor subclasses couple with text composition at
run-time to provide text layout
 Whenever text composition has to find line breaks, forwards the
responsibility to its current Compositor object.
How Design Patterns Solve Design Problems.
 The problems
 Finding Appropriate Objects
 Determining Object Granularity
 Specifying Object Interfaces
 Specifying Object Implementations
 Putting Reuse Mechanisms to Work
 Relating Run-Time and Compile-Time Structures.
 Designing for Change
Finding Appropriate Objects
 To decomposing a system, we must consider:
 encapsulation, granularity, dependency, flexibility,
performance, evolution, reusability, …
 Strict modeling of the real world may lead to
inflexibility.
 The abstractions that emerge during design are
key to making a design flexible.
 Design patterns help you identify less-obvious
abstractions and the objects that can capture
them.
Determining Object Granularity
 Objects can vary tremendously in size and
number.
 Design patterns address this issue as well.
 The patterns:
Facade, Flyweight, AbstractFactory, Builder, Vi
sitor, Command …
Specifying Object Interface
 Interface are fundamental in OO system.
 signature, type, supertype, dynamic
binding, polymorphism.
 Design patterns help you define interfaces by
identifying their key elements and the kind of
data that get sent across an interface.
 A pattern also tell you what not to put.
 Memento, Decorator, Proxy, Visitor
Specifying Object Implementation
 About the implementation:
 Object’s implementation is defined by class.
 Objects are created by instantiating a class.
 New classes can be defined by class inheritance.
(subclass and parent class).
 abstract class and concrete classes.
 A class may override an operation in the parent
class.
 Mixin class is a class that’s intended to provide
an optional interface or functionality.
Specifying Object Implementation
 The issues:
 Class versus Interface Inheritance.
 Programming to an Interface, not an
implementation.
Class versus Interface Inheritance(1)
 The difference between class and type:
 class defines the implementation.
 type refers to the interface.
 An object can have many types, and objects of
different classes can have the same type.
 In some languages like C++, Eiffel, classes
specify both an object’s type and its
implementation.
Class versus Interface Inheritance(2)
 Class inheritance versus interface inheritance
 class inheritance defines an object’s
implementation in terms of another object’s
implementation. (code and representation sharing).
 interface inheritance define when an object can be
used in place of another. (subtyping)
Class versus Interface Inheritance(3)
 Though most programming language don’t
support the distinction between interface and
implementation inheritance, people should
make the distinction in practice.
 Related patterns: Chain of Responsibility,
Composite, Command, Observer, State,
Strategy.
Programming to an interface,
not an Implementation
 Implementation reuse is only half of the
purpose of inheritance.
 Two benefits manipulating objects solely in
terms of interface:
 Clients remain unaware of the specific types of
objects they use.
 Clients remain unaware of the classes implementing
the objects.
interface, not an
Implementation(2)
 Declare variables using an interface defined by
an abstract class.
 Instantiate concrete classes somewhere.
 The creational patterns make the instantiation
possible.
 Abstract Factory, Builder, Factory
Method, Prototype, Singleton.
Putting Reuse Mechanisms to Work
 Inheritance versus Composition
 Delegation
 Inheritance versus Parameterized
Types
Inheritance versus Composition
 Inheritance is referred to as white-box reuse.
 Object composition: assembling or composing
objects to get more complex objects. referred
as black-box reuse.
Reuse by Inheritance
 The advantages:
 Defined statically at compile-time and is
straightforward to use.
 Easier to modify the implementation being reused.
 Reuse by overrides some but not all operations.
 The disadvantages:
 Can not change the implementations at run-time.
 Parent classes define part of the sub-classes’
physical representation. (inheritance breaks
encapsulation)
Reuse by Composition
 Composition requires objects to respect each
others’ interfaces. So we don’t break
encapsulation.
 Any object can be replaced at run-time by
another as long as it has the same type.
 Reduce the implementation dependencies.
 The classes and class hierarchies will remain
small.
Favor object composition over
class inheritance
 You should be able to get all the functionality
you need by assembling existing
components.
 You may use inheritance to define new
components if the existing components are
not enough.
 Designs are often made more reusable by
depending more on object composition.
Delegation(1)
 A way of making composition as powerful as
inheritance.
 A receiving object delegates operations to its
delegate.
Window
Area()
Rectangle
Area()
width
height
Delegation(2)
 The advantage:
 easy to compose behaviors at run-time
 easy to change the way they’re composed.
 Disadvantage:
 Dynamic, highly parameterized software is harder
to understand than static software.
 run-time inefficiencies.
 A good choice when it simplifiers more than
it complicates.
Delegation(3)
 The design patterns using delegation:
 State, Strategy, Visitor
 Less heavily: Mediator, Chain of
Responsibility, Bridge.
Inheritance versus
Parameterized Types
 generics (Ada, Eiffel) or templates(C++)
 A third way to reuse: Lets you define a
type without specifying all the other types (as
parameters) it uses.
Compare the three reuse methods
 Object composition lets you change the
behavior being composed at run-time. It
requires indirection and can be less efficient.
 Inheritance lets you provide default
implementation, and lets you override them.
 Parameterized types let you change the
types that a class can use.
Relating Run-Time and Compile-Time Structures(1)
 An object oriented program’s run-time structure
often bears little resemblance to its code
structure.
Aggregation and Acquaintance
 Aggregation: one object owns or is
responsible for another object.
 Acquaintance: an object merely knows of
another object. (also called ‘association’ or
‘using’)
 Aggregation and acquaintance are similar.
They are determined more by intent than by
language mechanisms.
 They are significantly different at the run-time.
Relating Run-Time and
Compile-Time Structures(2)
 We can not reveal everything about how a
system will work.
 The system’s run-time structure must be
imposed more by designer.
 Many design patterns capture the distinction
between compile-time and run-time structures:
 Composite, Decorator, Chain of Responsibility.
Designing for Change
 A design that doesn’t take change into account
risks major redesign in the future.
 Design patterns help you avoid this by ensuring
that a system can change in specific ways.
Common causes of redesign
 Creating an object by specifying a class
explicitly.
 Abstract Factory, Factory Method, Prototype.
 Dependence on specific operations:
 Chain of Responsibility, Command.
 Dependence on hardware and software
platform
 Chain of Responsibility, Command
Common causes of redesign(2)
 Dependence on object representations or
implementations
 Abstract Factory, Bridge, Memento, Proxy.
 Algorithm dependencies
 Builder, Iterator, Strategy, Template Method, Visitor.
 Tight coupling
 Abstract Factory, Bridge, Chain of
Responsibility, Command, Facade, Mediator, Obser
ver.
Common causes of redesign(3)
 Extending functionality by subclassing
 Bridge, Chain of Responsibility, Composite,
Decorator, Observer, Strategy.
 Inability to alter conveniently
 Adapter, Decorator, Visitor
The flexibility for different kind of software
 Application Programs
 Toolkits
 Frameworks
Using design patterns for
application programs
 internal reuse, maintainability, and extension
are high priorities.
 Design patterns increase internal reuse by
reduce the dependencies.
 Design patterns make an application more
maintainable when they’re used to limit
platform dependencies and to layer a system.
 Reduce coupling also enhances extensibility.
Using design patterns for toolkits
 Toolkits is a set of related and reusable classes
designed to provide useful, general-purpose
functionality.
 Toolkits emphasize code reuse.
 The designer should avoid assumptions and
dependencies that can limit the toolkit’s
flexibility.
Using design patterns for frameworks
 A framework is a set of cooperating classes
that make up a reusable design design for a
specific class of software.
 A framework defines:
 over-all structure
 its partitioning into classes and objects.
 key responsibilities thereof,
 the way the objects collaborate, and the control.
 A framework emphasize design reuse.
Using design patterns for
frameworks(2)
 When you use a framework, you reuse the
main body, and write the code it calls.
 The software have the similar structure. They
are easier to maintain.
 Designing a frameworks is the hardest one.
Using design patterns for frameworks(3)
 The most critical issues for framewrok design:
 As flexible and extensible as possible.
 Loose coupling between the elements.
 A framework using design patterns is far more
likely to achieve high levels of design and code
reuse than the one doesn’t.
 Design patterns can enhance the
documentation of the framework.
Patterns vs Frameworks
 Design patterns are more abstract than
frameworks.
 Design patterns are smaller architectural
elements.
 Design patterns are less specialized than
framework.
Patterns vs Frameworks
 Patterns are lower-level than frameworks
 Frameworks typically employ many patterns:
 Factory
 Strategy
 Composite
 Observer
 Done well, patterns are the “plumbing” of a
framework
How to select a design pattern
 Approaches to finding the design patterns:
 Consider how design patterns solve design
problems.
 Scan intent sections.
 Study how patterns interrelate.
 Study patterns of like purpose.
 Examine a cause of redesign.
 Consider what should be variable in your
design.(see table 1.2)
Where They are Used
 Object-Oriented programming languages [and
paradigm] are more amenable to implementing
design patterns
 Procedural languages: need to define
 Inheritance
 Polymorphism
 Encapsulation
When to Use Patterns
 Solutions to problems that recur with variations
 No need for reuse if problem only arises in one context
 Solutions that require several steps:
 Not all problems need all steps
 Patterns can be overkill if solution is a simple linear set of
instructions
 Solutions where the solver is more interested in the
existence of the solution than its complete derivation
 Patterns leave out too much to be useful to someone who really
wants to understand
 They can be a temporary bridge
Suggestions for Effective Use
 Do not recast everything as a pattern
 Instead, develop strategic domain patterns and
reuse existing tactical patterns
 Institutionalize rewards for developing patterns
 Directly involve pattern authors with application
developers and domain experts
 Clearly document when patterns apply and do
not apply
 Manage expectations carefully.
How to use a design pattern
 A step-by-step approach:
 Read the pattern once through for an overview.
 Go back and study the Structure, Participants, and
Collaborations sections.
 Look at the sample Code section to see a concrete
example of the pattern in Code.
 Choose names for pattern participants that are
meaningful in the application context.
How to use a design
pattern(2)
 Define the classes.
 Define application-specific names for
operations in the pattern.
 Implement the operations to carry out the
responsibilities and collaborations in the pattern.
Benefits of Design Patterns
 Design patterns enable large-scale reuse of
software architectures and also help document
systems
 Patterns explicitly capture expert knowledge
and design tradeoffs and make it more widely
available
 Patterns help improve developer
communication
 Pattern names form a common vocabulary
 Patterns help ease the transition to OO
technology
103
Benefits of Design Patterns
 Enhance understanding, restructuring, & team
communication
 Basis for automation
 Transcends language-centric biases/myopia
 Abstracts away from many unimportant details
Drawbacks to Design Patterns
 Patterns do not lead to direct code reuse
 Patterns are deceptively simple
 Teams may suffer from pattern overload
 Patterns are validated by experience and
discussion rather than by automated testing
 Integrating patterns into a software
development process is a human-intensive
activity.
105
Drawbacks to Design Patterns
 Require significant tedious & error-prone
human effort to handcraft pattern
implementations design reuse
 May limit design options
 Leaves some important details unresolved
Design Patterns are NOT
 Designs that can be encoded in classes and
reused as is (i.e., linked lists, hash tables)
 Complex domain-specific designs (for an entire
application or subsystem)
 They are:
 “Descriptions of communicating objects and classes
that are customized to solve a general design
problem in a particular context.”
107
Modified UML/OMT Notation
Exapmle: Model-View-Controller Pattern
 MVC consists of three kinds of objects:
 Model – the application object
 View – UI (screen presentation)
 Controller – defines the way the UI reacts to user
inputs
MVC – What Is the Problem?
 The same enterprise data needs to be
accessed when presented in different views:
e.g. HTML, JFC/swing, XML
 The same enterprise data needs to be updated
through different interactions
 Supporting multiple types of views and
interactions should not impact the components
that provide the core functionality of the
enterprise application
MVC – Solution
 Separate core business model functionality
from the presentation and control logic that
uses this functionality
 Allows multiple views to share the same
enterprise data model
 Makes supporting multiple clients easier to
implement, test, and maintain
MVC Structure
MVC – Responsibilities
 Model - the model represents enterprise data
and the business rules that govern access to
and updates of this data
 View -the view renders the contents of a
model. It accesses enterprise data through the
model and specifies how that data should be
presented
 Controller - the controller translates
interactions with the view into actions to be
performed by the model
MVC – Class Diagram
MVC – Class Diagram
Observer Pattern
Strategy Pattern
MVC – Class Diagram
(including interfaces)
MVC – Class Diagram (including interfaces)
controller
view
model
Observer Pattern
Class Diagram
Design Patterns
Observer Pattern
 Define a one-to-many dependency, all the
dependents are notified and updated
automatically
 The interaction is known as publish-subscribe
or subscribe-notify
 Avoiding observer-specific update protocol:
pull model vs. push model
 Other consequences and open issues
Design Patterns
Composite Pattern
 View can be nested
 Described by the Composite design pattern
seen in the lecture
Design Patterns
Strategy Pattern – Class Diagram
Design Patterns
Strategy Pattern
 Define family of algorithms, encapsulates them
and make them interchangeable
 Eliminate conditional statements
 Cons: communication overhead, increase
number of objects
122
Example: OBSERVER
Three Tier Model
Example: Stock Quote Service
Real time
Market Data
Feed
Stock Quotes
Customer
Customer
Customer Customer
Customer
Observers
Observer Pattern
 Intent:
 Define a one-to-many dependency between objects
so that when one object changes state, all its
dependents are notified and updated automatically
 Key forces:
 There may be many observers
 Each observer may react differently to the same
notification
 The subject should be as decoupled as possible
from the observers to allow observers to change
independently of the subject
Structure of Observer Pattern
+notify()
+attach(in Observer)
+detach(in Observer)
Subject
+getState()
-subjectSate
ConcreteSubject
+update()
Observer
+update()
ConcreteObserver
1
*
1
*
return subjectState observerState = subject->getState()
for all observers obs
{
obs->update()
}
Collaborations in Observer Pattern
S1 : ConcreteSubject obs1 : ConcreteObserver obs2 : ConcreteObserver
setState()
notify()
update()
getState()
update()
getState()
128
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
129
OBSERVER object behavioral
class ProxyPushConsumer : public // …
virtual void push (const CORBA::Any &event) {
for (std::vector<PushConsumer>::iterator i
(consumers.begin ()); i != consumers.end (); i++)
(*i).push (event);
}
CORBA Notification Service
example using C++
Standard Template Library
(STL) iterators (which is an
example of the Iterator
pattern from GoF)
class MyPushConsumer : public // ….
virtual void push
(const CORBA::Any &event) { /* consume the event. */ }
130
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 Message Service)
 Mailing lists
Conclusions
 Design Patterns provide a foundation for further
understanding of:
 Object-Oriented design
 Software Architecture
 Understanding patterns can take some time
 Re-reading them over time helps
 As does applying them in your own designs!

Contenu connexe

Tendances

Design Pattern in Software Engineering
Design Pattern in Software EngineeringDesign Pattern in Software Engineering
Design Pattern in Software EngineeringManish Kumar
 
Creational Patterns
Creational PatternsCreational Patterns
Creational PatternsAsma CHERIF
 
Responsibility Driven Design
Responsibility Driven DesignResponsibility Driven Design
Responsibility Driven DesignHarsh Jegadeesan
 
04 designing architectures
04 designing architectures04 designing architectures
04 designing architecturesMajong DevJfu
 
CS8592 Object Oriented Analysis & Design - UNIT IV
CS8592 Object Oriented Analysis & Design - UNIT IV CS8592 Object Oriented Analysis & Design - UNIT IV
CS8592 Object Oriented Analysis & Design - UNIT IV pkaviya
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan GoleChetan Gole
 
Cse 6007 fall2012
Cse 6007 fall2012Cse 6007 fall2012
Cse 6007 fall2012rhrashel
 
OO Development 5 - Analysis
OO Development 5 - AnalysisOO Development 5 - Analysis
OO Development 5 - AnalysisRandy Connolly
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural PatternsSameh Deabes
 
DE1b Report format
DE1b Report format DE1b Report format
DE1b Report format Juhi Shah
 
Design in construction
Design in constructionDesign in construction
Design in constructionAsha Sari
 
Writing good C# code for good cloud applications - Draft Oct 20, 2014
Writing good C# code for good cloud applications - Draft Oct 20, 2014Writing good C# code for good cloud applications - Draft Oct 20, 2014
Writing good C# code for good cloud applications - Draft Oct 20, 2014Marco Parenzan
 
02 problem solving_02
02 problem solving_0202 problem solving_02
02 problem solving_02Nika Stuard
 
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPTCS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPTleela rani
 
Generation of Automatic Code using Design Patterns
Generation of Automatic Code using Design PatternsGeneration of Automatic Code using Design Patterns
Generation of Automatic Code using Design PatternsIRJET Journal
 

Tendances (19)

Design Pattern in Software Engineering
Design Pattern in Software EngineeringDesign Pattern in Software Engineering
Design Pattern in Software Engineering
 
Creational Patterns
Creational PatternsCreational Patterns
Creational Patterns
 
Responsibility Driven Design
Responsibility Driven DesignResponsibility Driven Design
Responsibility Driven Design
 
04 designing architectures
04 designing architectures04 designing architectures
04 designing architectures
 
CS8592 Object Oriented Analysis & Design - UNIT IV
CS8592 Object Oriented Analysis & Design - UNIT IV CS8592 Object Oriented Analysis & Design - UNIT IV
CS8592 Object Oriented Analysis & Design - UNIT IV
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
Cse 6007 fall2012
Cse 6007 fall2012Cse 6007 fall2012
Cse 6007 fall2012
 
OO Development 5 - Analysis
OO Development 5 - AnalysisOO Development 5 - Analysis
OO Development 5 - Analysis
 
Design engineering
Design engineeringDesign engineering
Design engineering
 
Patterns Overview
Patterns OverviewPatterns Overview
Patterns Overview
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
 
DE1b Report format
DE1b Report format DE1b Report format
DE1b Report format
 
010821+presentation+oti.ppt
010821+presentation+oti.ppt010821+presentation+oti.ppt
010821+presentation+oti.ppt
 
Designpattern
DesignpatternDesignpattern
Designpattern
 
Design in construction
Design in constructionDesign in construction
Design in construction
 
Writing good C# code for good cloud applications - Draft Oct 20, 2014
Writing good C# code for good cloud applications - Draft Oct 20, 2014Writing good C# code for good cloud applications - Draft Oct 20, 2014
Writing good C# code for good cloud applications - Draft Oct 20, 2014
 
02 problem solving_02
02 problem solving_0202 problem solving_02
02 problem solving_02
 
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPTCS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
 
Generation of Automatic Code using Design Patterns
Generation of Automatic Code using Design PatternsGeneration of Automatic Code using Design Patterns
Generation of Automatic Code using Design Patterns
 

En vedette

Analytical approach on design theories of christopher alexander
Analytical approach on design theories of christopher alexanderAnalytical approach on design theories of christopher alexander
Analytical approach on design theories of christopher alexanderShabnam Golkarian
 
Design & Thinking in Luster
Design & Thinking in LusterDesign & Thinking in Luster
Design & Thinking in LusterJason Chung
 
Design pattern strategy pattern 策略模式
Design pattern strategy pattern 策略模式Design pattern strategy pattern 策略模式
Design pattern strategy pattern 策略模式Bill Lin
 
前端魔法師召集令
前端魔法師召集令前端魔法師召集令
前端魔法師召集令Jason Chung
 
Design Pattern - Factory Pattern
Design Pattern - Factory PatternDesign Pattern - Factory Pattern
Design Pattern - Factory PatternLi-Wei Yao
 
設計模式的解析與活用:分析
設計模式的解析與活用:分析設計模式的解析與活用:分析
設計模式的解析與活用:分析Kane Shih
 
The city as metabolism slides intro
The city as metabolism slides introThe city as metabolism slides intro
The city as metabolism slides introFionn MacKillop
 
The 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryThe 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryachraf_ing
 
Designing Object Oriented Software - lecture slides 2013
Designing Object Oriented Software - lecture slides 2013Designing Object Oriented Software - lecture slides 2013
Designing Object Oriented Software - lecture slides 2013Jouni Smed
 
Factory Pattern in Luster
Factory Pattern in LusterFactory Pattern in Luster
Factory Pattern in LusterJason Chung
 
Software archiecture lecture09
Software archiecture   lecture09Software archiecture   lecture09
Software archiecture lecture09Luktalja
 
Christopher Alexander: Elements Of Style
Christopher Alexander: Elements Of StyleChristopher Alexander: Elements Of Style
Christopher Alexander: Elements Of StyleMatthias Mueller-Prove
 

En vedette (20)

Analytical approach on design theories of christopher alexander
Analytical approach on design theories of christopher alexanderAnalytical approach on design theories of christopher alexander
Analytical approach on design theories of christopher alexander
 
Design & Thinking in Luster
Design & Thinking in LusterDesign & Thinking in Luster
Design & Thinking in Luster
 
Maker in Luster
Maker in LusterMaker in Luster
Maker in Luster
 
Design pattern strategy pattern 策略模式
Design pattern strategy pattern 策略模式Design pattern strategy pattern 策略模式
Design pattern strategy pattern 策略模式
 
策略模式
策略模式 策略模式
策略模式
 
前端魔法師召集令
前端魔法師召集令前端魔法師召集令
前端魔法師召集令
 
Design Pattern - Factory Pattern
Design Pattern - Factory PatternDesign Pattern - Factory Pattern
Design Pattern - Factory Pattern
 
Urban Block
Urban BlockUrban Block
Urban Block
 
設計模式的解析與活用:分析
設計模式的解析與活用:分析設計模式的解析與活用:分析
設計模式的解析與活用:分析
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 
Factory Patterns
Factory PatternsFactory Patterns
Factory Patterns
 
The city as metabolism slides intro
The city as metabolism slides introThe city as metabolism slides intro
The city as metabolism slides intro
 
The 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryThe 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summary
 
Designing Object Oriented Software - lecture slides 2013
Designing Object Oriented Software - lecture slides 2013Designing Object Oriented Software - lecture slides 2013
Designing Object Oriented Software - lecture slides 2013
 
Composite Design Pattern
Composite Design PatternComposite Design Pattern
Composite Design Pattern
 
Factory Pattern in Luster
Factory Pattern in LusterFactory Pattern in Luster
Factory Pattern in Luster
 
Software archiecture lecture09
Software archiecture   lecture09Software archiecture   lecture09
Software archiecture lecture09
 
Pictorious 2017 Update
Pictorious 2017 UpdatePictorious 2017 Update
Pictorious 2017 Update
 
Christopher Alexander: Elements Of Style
Christopher Alexander: Elements Of StyleChristopher Alexander: Elements Of Style
Christopher Alexander: Elements Of Style
 
Burnham Fb Cs Final 25sep09
Burnham Fb Cs Final 25sep09Burnham Fb Cs Final 25sep09
Burnham Fb Cs Final 25sep09
 

Similaire à Cs 1023 lec 9 design pattern (week 2)

Design pattern & categories
Design pattern & categoriesDesign pattern & categories
Design pattern & categoriesHimanshu
 
Software Patterns
Software PatternsSoftware Patterns
Software Patternskim.mens
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design PatternSanae BEKKAR
 
Mit3033 software architecture
Mit3033  software architectureMit3033  software architecture
Mit3033 software architecturesmumbahelp
 
SADP PPTs of all modules - Shanthi D.L.pdf
SADP PPTs of all modules - Shanthi D.L.pdfSADP PPTs of all modules - Shanthi D.L.pdf
SADP PPTs of all modules - Shanthi D.L.pdfB.T.L.I.T
 
Patterns of Interaction Description Including Aspects of Constraints
Patterns of Interaction Description Including Aspects of ConstraintsPatterns of Interaction Description Including Aspects of Constraints
Patterns of Interaction Description Including Aspects of ConstraintsJuan Manuel Gonzalez Calleros
 
Contemporary Software Engineering Practices Together With Enterprise
Contemporary Software Engineering Practices Together With EnterpriseContemporary Software Engineering Practices Together With Enterprise
Contemporary Software Engineering Practices Together With EnterpriseKenan Sevindik
 
Unit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptxUnit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptxDrYogeshDeshmukh1
 
Deliverables that Clarify, Focus, and Improve Design
Deliverables that Clarify, Focus, and Improve DesignDeliverables that Clarify, Focus, and Improve Design
Deliverables that Clarify, Focus, and Improve DesignBen Peachey
 
Design Patterns
Design PatternsDesign Patterns
Design Patternsfrgo
 

Similaire à Cs 1023 lec 9 design pattern (week 2) (20)

.Net design pattern
.Net design pattern.Net design pattern
.Net design pattern
 
Design pattern & categories
Design pattern & categoriesDesign pattern & categories
Design pattern & categories
 
Design Pattern
Design PatternDesign Pattern
Design Pattern
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Stoop 430-design patternsintro
Stoop 430-design patternsintroStoop 430-design patternsintro
Stoop 430-design patternsintro
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Patterns
PatternsPatterns
Patterns
 
Mit3033 software architecture
Mit3033  software architectureMit3033  software architecture
Mit3033 software architecture
 
SADP PPTs of all modules - Shanthi D.L.pdf
SADP PPTs of all modules - Shanthi D.L.pdfSADP PPTs of all modules - Shanthi D.L.pdf
SADP PPTs of all modules - Shanthi D.L.pdf
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Patterns of Interaction Description Including Aspects of Constraints
Patterns of Interaction Description Including Aspects of ConstraintsPatterns of Interaction Description Including Aspects of Constraints
Patterns of Interaction Description Including Aspects of Constraints
 
Modest Formalization of Software Design Patterns
Modest Formalization of Software Design PatternsModest Formalization of Software Design Patterns
Modest Formalization of Software Design Patterns
 
Contemporary Software Engineering Practices Together With Enterprise
Contemporary Software Engineering Practices Together With EnterpriseContemporary Software Engineering Practices Together With Enterprise
Contemporary Software Engineering Practices Together With Enterprise
 
Unit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptxUnit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptx
 
Deliverables that Clarify, Focus, and Improve Design
Deliverables that Clarify, Focus, and Improve DesignDeliverables that Clarify, Focus, and Improve Design
Deliverables that Clarify, Focus, and Improve Design
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design Patterns.ppt
Design Patterns.pptDesign Patterns.ppt
Design Patterns.ppt
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Design patterns
Design patternsDesign patterns
Design patterns
 

Plus de stanbridge

Micro Lab 3 Lecture
Micro Lab 3 LectureMicro Lab 3 Lecture
Micro Lab 3 Lecturestanbridge
 
Creating a poster v2
Creating a poster v2Creating a poster v2
Creating a poster v2stanbridge
 
Creating a poster
Creating a posterCreating a poster
Creating a posterstanbridge
 
OT 5018 Thesis Dissemination
OT 5018 Thesis DisseminationOT 5018 Thesis Dissemination
OT 5018 Thesis Disseminationstanbridge
 
Ot5101 005 week 5
Ot5101 005 week 5Ot5101 005 week 5
Ot5101 005 week 5stanbridge
 
Ot5101 005 week4
Ot5101 005 week4Ot5101 005 week4
Ot5101 005 week4stanbridge
 
Compliance, motivation, and health behaviors
Compliance, motivation, and health behaviors Compliance, motivation, and health behaviors
Compliance, motivation, and health behaviors stanbridge
 
Ch 5 developmental stages of the learner
Ch 5   developmental stages of the learnerCh 5   developmental stages of the learner
Ch 5 developmental stages of the learnerstanbridge
 
OT 5101 week2 theory policy
OT 5101 week2 theory policyOT 5101 week2 theory policy
OT 5101 week2 theory policystanbridge
 
OT 5101 week3 planning needs assessment
OT 5101 week3 planning needs assessmentOT 5101 week3 planning needs assessment
OT 5101 week3 planning needs assessmentstanbridge
 
NUR 304 Chapter005
NUR 304 Chapter005NUR 304 Chapter005
NUR 304 Chapter005stanbridge
 
NUR 3043 Chapter007
NUR 3043 Chapter007NUR 3043 Chapter007
NUR 3043 Chapter007stanbridge
 
NUR 3043 Chapter006
NUR 3043 Chapter006NUR 3043 Chapter006
NUR 3043 Chapter006stanbridge
 
NUR 3043 Chapter004
NUR 3043 Chapter004NUR 3043 Chapter004
NUR 3043 Chapter004stanbridge
 
3043 Chapter009
3043 Chapter0093043 Chapter009
3043 Chapter009stanbridge
 
3043 Chapter008
 3043 Chapter008 3043 Chapter008
3043 Chapter008stanbridge
 
Melnyk ppt chapter_21
Melnyk ppt chapter_21Melnyk ppt chapter_21
Melnyk ppt chapter_21stanbridge
 
Melnyk ppt chapter_22
Melnyk ppt chapter_22Melnyk ppt chapter_22
Melnyk ppt chapter_22stanbridge
 

Plus de stanbridge (20)

Micro Lab 3 Lecture
Micro Lab 3 LectureMicro Lab 3 Lecture
Micro Lab 3 Lecture
 
Creating a poster v2
Creating a poster v2Creating a poster v2
Creating a poster v2
 
Creating a poster
Creating a posterCreating a poster
Creating a poster
 
Sample poster
Sample posterSample poster
Sample poster
 
OT 5018 Thesis Dissemination
OT 5018 Thesis DisseminationOT 5018 Thesis Dissemination
OT 5018 Thesis Dissemination
 
Ot5101 005 week 5
Ot5101 005 week 5Ot5101 005 week 5
Ot5101 005 week 5
 
Ot5101 005 week4
Ot5101 005 week4Ot5101 005 week4
Ot5101 005 week4
 
Compliance, motivation, and health behaviors
Compliance, motivation, and health behaviors Compliance, motivation, and health behaviors
Compliance, motivation, and health behaviors
 
Ch 5 developmental stages of the learner
Ch 5   developmental stages of the learnerCh 5   developmental stages of the learner
Ch 5 developmental stages of the learner
 
OT 5101 week2 theory policy
OT 5101 week2 theory policyOT 5101 week2 theory policy
OT 5101 week2 theory policy
 
OT 5101 week3 planning needs assessment
OT 5101 week3 planning needs assessmentOT 5101 week3 planning needs assessment
OT 5101 week3 planning needs assessment
 
Ot5101 week1
Ot5101 week1Ot5101 week1
Ot5101 week1
 
NUR 304 Chapter005
NUR 304 Chapter005NUR 304 Chapter005
NUR 304 Chapter005
 
NUR 3043 Chapter007
NUR 3043 Chapter007NUR 3043 Chapter007
NUR 3043 Chapter007
 
NUR 3043 Chapter006
NUR 3043 Chapter006NUR 3043 Chapter006
NUR 3043 Chapter006
 
NUR 3043 Chapter004
NUR 3043 Chapter004NUR 3043 Chapter004
NUR 3043 Chapter004
 
3043 Chapter009
3043 Chapter0093043 Chapter009
3043 Chapter009
 
3043 Chapter008
 3043 Chapter008 3043 Chapter008
3043 Chapter008
 
Melnyk ppt chapter_21
Melnyk ppt chapter_21Melnyk ppt chapter_21
Melnyk ppt chapter_21
 
Melnyk ppt chapter_22
Melnyk ppt chapter_22Melnyk ppt chapter_22
Melnyk ppt chapter_22
 

Dernier

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 

Dernier (20)

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 

Cs 1023 lec 9 design pattern (week 2)

  • 1. Background-Origins of Design Patterns  Building Architecture pattern  Christopher Alexander, architect  A Pattern Language---Towns, Buildings, Construction (1977)  Timeless Way of Building (1979)  “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.” ---Christopher Alexander, Sara Ishikawa, Murray Silverstein, Max Jacobson, Ingrid Fiksdahl-King, Shlomo Angel, “A Pattern Language: Towns/Buildings/ Construction”, Oxford University Press, New York, 1977  …
  • 2. Background  In 1987, Kent Beck and Ward Cunningham began experimenting with the idea of applying patterns to programming and presented their results at the OOPSLA conference that year. ----Beck, Kent; Ward Cunningham (September 1987). "Using Pattern Languages for Object-Oriented Program". OOPSLA '87 workshop on Specification and Design for Object-Oriented Programming. OOPSLA '87. http://c2.com/doc/oopsla87.html
  • 3. Background  In software engineering  Search for recurring successful designs – emergent designs from practice (via trial and error)  Supporting higher levels of reuse (i.e., reuse of designs) is quite challenging
  • 4. What is a Design Pattern?  In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. --- http://en.wikipedia.org/wiki/Design_pattern_(computer_s cience)
  • 5. What Is a Design Pattern?  A design pattern  Is a common solution to a recurring problem in design  Abstracts a recurring design structure  Comprises class and/or object  Dependencies  Structures  Interactions  Conventions  Names & specifies the design structure explicitly  Distils design experience
  • 6. Re-use Code VS. Design  Code re-use  Don’t reinvent the wheel  Requires clean, elegant, understandable, general, stable code  leverage previous work  Design re-use  Don’t reinvent the wheel  Requires a precise understanding of common, recurring designs  leverage previous work
  • 7. Patterns vs “Design”  Patterns are design  But: patterns transcend the “identify classes and associations” approach to design  Instead: learn to recognize patterns in the problem space and translate to the solution  Patterns can capture OO design principles within a specific domain  Patterns provide structure to “design”
  • 8. Design Patterns VS. Architecture Patterns  Design patterns reside in the domain of modules and interconnections.  At a higher level there are Architectural patterns that are larger in scope, usually describing an overall pattern followed by an entire system.
  • 9. Design Patterns VS. Architecture Patterns  Design Patterns represent a lower level of system structure than “software architecture” (cf: seven levels of A)  Patterns can be applied to architecture:  Mowbray and Malveau  Buschmann et al  Schmidt et al  Architectural patterns tend to be focussed on middleware. They are good at capturing:  Concurrency  Distribution  Synchronization
  • 10. Why design patterns in SA?  If you’re a software engineer, you should know about them anyway.  There are many architectural patterns published, and the Design Patterns is a prerequisite to understanding these:  Mowbray and Malveau – CORBA Design Patterns  Schmidt et al – Pattern-Oriented Software Architecture  Design Patterns help you break out of first- generation OO thought patterns
  • 11. The seven layers of architecture* Global architecture Enterprise architecture System architecture Application architecture Macro-architecture Micro-architecture Objects ORB OO architecture Frameworks Subsystem Design patterns OO programming
  • 12. Design Patterns VS. Software Patterns  Not all software patterns are design patterns.  For instance, algorithms solve computational problems rather than software design problems.  Design problem  Programming problem  Computational problem
  • 13. What Makes it a Pattern?  A Pattern must:  Solve a problem and be useful  Have a context and can describe where the solution can be used  Recur in relevant situations  Provide sufficient understanding to tailor the solution  Have a name and be referenced consistently
  • 14. Description of a Design Pattern  Description of communicating objects and classes that are customized to solve a general design problem in a particular context.  Language- & implementation-independent  A “micro-architecture”  Adjunct to existing methodologies (RUP, Fusion, SCRUM, etc.)
  • 15. Description of a Design Pattern  Graphical notation is generally not sufficient  In order to reuse design decisions the alternatives and trade-offs that led to the decisions are critical knowledge  Concrete examples are also important  The history of the why, when, and how set the stage for the context of usage
  • 16. Description of a Design Pattern  Describe a recurring design structure  Defines a common vocabulary  Abstracts from concrete designs  Identifies classes, collaborations, and responsibilities  Describes applicability, trade-offs, and consequences  Formats of pattern writers vary, but a pattern description usually has at least these four things.  pattern name  problem  solution  Consequences
  • 17. Pattern Name  A handle used to describe:  a design problem  its solutions  its consequences  Increases design vocabulary  Makes it possible to design at a higher level of abstraction  Enhances communication  “The Hardest part of programming is coming up with good variable [function, and type] names.”
  • 18. Problem  Describes when to apply the pattern  Explains the problem and its context  May describe specific design problems and/or object structures  May contain a list of preconditions that must be met before it makes sense to apply the pattern
  • 19. Solution  Describes the elements that make up the  design  relationships  responsibilities  collaborations  Does not describe specific concrete implementation  Abstract description of design problems and how the pattern solves it
  • 20. Consequences  Results and trade-offs of applying the pattern  Critical for:  evaluating design alternatives  understanding costs  understanding benefits of applying the pattern  Includes the impacts of a pattern on a system’s:  flexibility  extensibility  portability
  • 21. Design Pattern Template  Pattern Name and Classification:  A descriptive and unique name that helps in identifying and referring to the pattern.  Intent:  A description of the goal behind the pattern and the reason for using it.  Also Known As:  Other names for the pattern.  Motivation (Forces):  A scenario consisting of a problem and a context in which this pattern can be used.  Applicability:  Situations in which this pattern is usable; the context for the pattern.  Structure:  A graphical representation of the pattern. Class diagrams and Interaction diagrams may be used for this purpose.  Participants:  A listing of the classes and objects used in the pattern and their roles in the design. 22
  • 22. Design Pattern Template  Collaboration:  A description of how classes and objects used in the pattern interact with each other.  Consequences:  A description of the results, side effects, and trade offs caused by using the pattern.  Implementation:  A description of an implementation of the pattern; the solution part of the pattern.  Sample Code:  An illustration of how the pattern can be used in a programming language.  Known Uses:  Examples of real usages of the pattern.  Related Patterns:  Other patterns that have some relationship with the pattern; discussion of the differences between the pattern and similar patterns.
  • 23. Goals of Design Patterns  Codify good design  Distil and disseminate experience  Aid to novices and experts alike  Abstract how to think about design  Give design structures explicit names  Common vocabulary  Reduced complexity  Greater expressiveness  Capture and preserve design information  Articulate design decisions succinctly  Improve documentation  Facilitate restructuring/refactoring  Patterns are interrelated  Additional flexibility
  • 24. Goals of Design Patterns  Design patterns can speed up the development process by providing tested, proven development paradigms.  Effective software design requires considering issues that may not become visible until later in the implementation.  Reusing design patterns helps to prevent subtle issues that can cause major problems, and it also improves code readability for coders and architects who are familiar with the patterns.
  • 25. Design Patterns Why Design Patterns?  Designing OO software is hard  Designing reusable OO software – harder  Experienced OO designers make good design  New designers tend to fall back on non-OO techniques used before  Experienced designers know something – what is it?
  • 26. Why Design Patterns?  Expert designers know not to solve every problem from first principles.  They reuse solutions.  These patterns make OO designs more flexible, elegant, and ultimately reusable.
  • 27. Two Major Principles of Object-Oriented Design  Program to an interface, not an implementation.  Favor object compositions over class inheritance.
  • 28. 29 OO Desgin  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
  • 29. 30 Recurring OO Design Structures  OO systems exhibit recurring structures that promote  abstraction  flexibility  modularity  elegance  find pertinent objects and factor them into classes at the right granularity.  define class interfaces and inheritance hierarchies  Establish key relationship among classes.
  • 30. OO Design is hard  The design should be specific to the problem at hand, but also general enough to address future problems and requirements.  Therein lies valuable design knowledge, the problem is  Capturing,  Communicating,  applying this knowledge
  • 31. Expert designers use patterns  When they find a good solution, they use it again and again.  The design patterns solve specific design problems and make OO designs more flexible, elegant, and ultimately reusable.  A designer who is familiar with patterns can apply them immediately to design problems.
  • 32. A design pattern can …  Make it easier to reuse successful designs and architectures.  Help you choose good design: make system reusable.  Improve the documentation and maintenance.
  • 33. Why Study Design Patterns?  Can reuse solutions.  Gives us a head start  Avoids the unanticipated things later  No need to reinvent the wheel  Establish common terminology  Design patterns provide a common point of reference  Easier to say, “We need some Strategies here.”  Provide a higher level prospective.  Frees us from dealing with the details too early.
  • 34. State of the Art  Notable Books:  Gamma, Erich; Richard Helm, Ralph Johnson, and John Vlissides (1995). Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley. ISBN 0-201-63361-2.  Schmidt, Douglas C.; Michael Stal, Hans Rohnert, Frank Buschmann (2000). Pattern-Oriented Software Architecture, Volume 2: Patterns for Concurrent and Networked Objects. John Wiley & Sons. ISBN 0- 471-60695-2.  Fowler, Martin (2002). Patterns of Enterprise Application Architecture. Addison-Wesley. ISBN 978-0321127426.  Hohpe, Gregor; Bobby Woolf (2003). Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions. Addison- Wesley. ISBN 0-321-20068-3.
  • 35. “Gang of Four” (GoF) Book Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley Publishing Company, 1995 This book solidified thinking about patterns and became the seminal Design Patterns text
  • 36. “Gang of Four” (GoF)  Dr. Erich Gamma, then Software Engineer, Taligent, Inc.; now at Object Technology International as the technical director of the Zurich lab in Switzerland.  Dr. Richard Helm, then Senior Technology Consultant, DMR Group; now at the Boston Consulting Group.  Dr. Ralph Johnson, then and now at University of Illinois, Computer Science Department; now a Research Associate Professor.  Dr. John Vlissides, then a researcher at IBM Thomas J. Watson Research Center.
  • 37. Patterns  This book defined 23 patterns, classified into three categories.  Creational patterns, which deal with the process of object creation.  Structural patterns, which deal primarily with the static composition and structure of classes and objects.  Behavioral patterns, which deal primarily with dynamic interaction among classes and objects.  Many other patterns have been introduced by others.  For example, the book Data Access Patterns by Clifton Nock introduces 4 decoupling patterns, 5 resource patterns, 5 I/O patterns, 7 cache patterns, and 4 concurrency patterns.  Hundreds of patterns have been documented since; other examples include telecommunications patterns, pedagogical patterns, analysis patterns, and indexing patterns.
  • 38. What’s in this book  Designs that have been applied more than once in different systems.  Although the patterns are not new, they are arranged in a new and accessible way.  Three categories:  Creational Patterns  Structural Patterns  Behavioral Patterns
  • 39. What’s not in this book  About concurrency or distributed programming or real-time programming.  application domain-specific patterns.  patterns about user interfaces  device drivers  OO databases.  But an expert should know the above.
  • 40. Types of Patterns  Creational patterns:  Deal with initializing and configuring classes and objects  Structural patterns:  Deal with decoupling interface and implementation of classes and objects  Composition of classes or objects  Behavioral patterns:  Deal with dynamic interactions among societies of classes and objects  How they distribute responsibility
  • 41. Classification of GoF Design Pattern Creational Structural Behavioral Factory Method Abstract Factory Builder Prototype Singleton Adapter Bridge Composite Decorator Flyweight Facade Proxy Interpreter Template Method Chain of Responsibility Command Iterator Mediator Memento Observer State Strategy Visitor
  • 42. Alternative Classification (Reverse engineering) Intent language-provided patterns structure-driven patterns behavior-driven patterns domain-specific patterns generic concepts Prototype Iterator Bridge Composite Adapter Facade Proxy Template Method Visitor Singleton Abstract Factory Factory Method Flyweight Chain of Responsibility Decorator Strategy State Observer Mediator Command Interpreter Memento Builder
  • 43. Creational Patterns  Abstract Factory:  Factory for building related objects  Builder:  Factory for building complex objects incrementally  Factory Method:  Method in a derived class creates associates  Prototype:  Factory for cloning new instances from a prototype  Singleton:  Factory for a singular (sole) instance
  • 44. Structural Patterns  Adapter:  Translator adapts a server interface for a client  Bridge:  Abstraction for binding one of many implementations  Composite:  Structure for building recursive aggregations  Decorator:  Decorator extends an object transparently  Facade:  Simplifies the interface for a subsystem  Flyweight:  Many fine-grained objects shared efficiently.  Proxy:  One object approximates another
  • 45. Behavioral Patterns  Chain of Responsibility:  Request delegated to the responsible service provider  Command:  Request is first-class object  Iterator:  Aggregate elements are accessed sequentially  Interpreter:  Language interpreter for a small grammar  Mediator:  Coordinates interactions between its associates  Memento:  Snapshot captures and restores object states privately
  • 46. Behavioral Patterns (cont.)  Observer:  Dependents update automatically when subject changes  State:  Object whose behavior depends on its state  Strategy:  Abstraction for selecting one of many algorithms  Template Method:  Algorithm with some steps supplied by a derived class  Visitor:  Operations applied to elements of a heterogeneous object structure
  • 47. Organization of Design Patterns  Two criterion are used to classify patterns:  Purpose  creational,  structural,  behavioral  Scope  Class  Object
  • 48. 50 Design Space for GoF Patterns Scope: domain over which a pattern applies Purpose: reflects what a pattern does
  • 49. Categorization Terms  Scope is the domain over which a pattern applies  Class Scope: relationships between base classes and their subclasses (static semantics)  Object Scope: relationships between peer objects  Some patterns apply to both scopes.
  • 50. Class::Creational  Abstracts how objects are instantiated  Hides specifics of the creation process  May want to delay specifying a class name explicitly when instantiating an object  Just want a specific protocol
  • 51. Example  Use Factory Method to instantiate members in base classes with objects created by subclasses  Abstract Application class: create application-specific documents conforming to a particular Document type  Application instantiates these Document objects by calling the factory method DoMakeDocument  Method is overridden in classes derived from Application  Subclass DrawApplication overrides DoMakeDocument to return a DrawDocument object
  • 52. Class:: Structural  Use inheritance to compose protocols or code  Example:  Adapter Pattern: makes one interface (Adaptee’s) conform to another  Gives a uniform abstraction of different interfaces  Class Adapter inherits privately from an Adaptee class  Adapter then expresses its interface in terms of the Adaptee’s.
  • 53. Class:: Behavioral  Captures how classes cooperate with their subclasses to satisfy semantics. Example:  Template Method: defines algorithms step by step.  Each step can invoke an abstract method (that must be defined by the subclass) or a base method.  Subclass must implement specific behavior to provide required services
  • 54. Object Scope  Object Patterns all apply various forms of non- recursive object composition.  Object Composition: most powerful form of reuse  Reuse of a collection of objects is better achieved through variations of their composition, rather than through sub classing.
  • 55. Object:: Creational  Abstracts how sets of objects are created Example:  Abstract Factory: create “product” objects through generic interface  Subclasses may manufacture specialized versions or compositions of objects as allowed by this generic interface  User Interface Toolkit: 2 types of scroll bars (Motif and Open Look)  Don’t want to hard-code specific one; an environment variable decides  Class Kit:  Encapsulates scroll bar creation (and other UI entities);  An abstract factory that abstracts the specific type of scroll bar to instantiate  Subclasses of Kit refine operations in the protocol to return specialized types of scroll bars.  Subclasses MotifKit and OpenLookKit each have scroll bar operation.
  • 56. Object:: Structural  Describe ways to assemble objects to realize new functionality  Added flexibility inherent in object composition due to ability to change composition at run-time  not possible with static class composition  Example:  Proxy: acts as convenient surrogate or placeholder for another object.  Remote Proxy: local representative for object in a different address space  Virtual Proxy: represent large object that should be loaded on demand  Protected Proxy: protect access to the original object
  • 57. Object:: Behavioral  Describes how a group of peer objects cooperate to perform a task that can be carried out by itself. Example:  Strategy Pattern: objectifies an algorithm  Text Composition Object: support different line breaking algorithms  Don’t want to hard-code all algs into text composition class/subclasses  Objectify different algs and provide them as Compositor subclasses (contains criteria for line breaking strategies)  Interface for Compositors defined by Abstract Compositor Class  Derived classes provide different layout strategies (simple line breaks, left/right justification, etc.)  Instances of Compositor subclasses couple with text composition at run-time to provide text layout  Whenever text composition has to find line breaks, forwards the responsibility to its current Compositor object.
  • 58. How Design Patterns Solve Design Problems.  The problems  Finding Appropriate Objects  Determining Object Granularity  Specifying Object Interfaces  Specifying Object Implementations  Putting Reuse Mechanisms to Work  Relating Run-Time and Compile-Time Structures.  Designing for Change
  • 59. Finding Appropriate Objects  To decomposing a system, we must consider:  encapsulation, granularity, dependency, flexibility, performance, evolution, reusability, …  Strict modeling of the real world may lead to inflexibility.  The abstractions that emerge during design are key to making a design flexible.  Design patterns help you identify less-obvious abstractions and the objects that can capture them.
  • 60. Determining Object Granularity  Objects can vary tremendously in size and number.  Design patterns address this issue as well.  The patterns: Facade, Flyweight, AbstractFactory, Builder, Vi sitor, Command …
  • 61. Specifying Object Interface  Interface are fundamental in OO system.  signature, type, supertype, dynamic binding, polymorphism.  Design patterns help you define interfaces by identifying their key elements and the kind of data that get sent across an interface.  A pattern also tell you what not to put.  Memento, Decorator, Proxy, Visitor
  • 62. Specifying Object Implementation  About the implementation:  Object’s implementation is defined by class.  Objects are created by instantiating a class.  New classes can be defined by class inheritance. (subclass and parent class).  abstract class and concrete classes.  A class may override an operation in the parent class.  Mixin class is a class that’s intended to provide an optional interface or functionality.
  • 63. Specifying Object Implementation  The issues:  Class versus Interface Inheritance.  Programming to an Interface, not an implementation.
  • 64. Class versus Interface Inheritance(1)  The difference between class and type:  class defines the implementation.  type refers to the interface.  An object can have many types, and objects of different classes can have the same type.  In some languages like C++, Eiffel, classes specify both an object’s type and its implementation.
  • 65. Class versus Interface Inheritance(2)  Class inheritance versus interface inheritance  class inheritance defines an object’s implementation in terms of another object’s implementation. (code and representation sharing).  interface inheritance define when an object can be used in place of another. (subtyping)
  • 66. Class versus Interface Inheritance(3)  Though most programming language don’t support the distinction between interface and implementation inheritance, people should make the distinction in practice.  Related patterns: Chain of Responsibility, Composite, Command, Observer, State, Strategy.
  • 67. Programming to an interface, not an Implementation  Implementation reuse is only half of the purpose of inheritance.  Two benefits manipulating objects solely in terms of interface:  Clients remain unaware of the specific types of objects they use.  Clients remain unaware of the classes implementing the objects.
  • 68. interface, not an Implementation(2)  Declare variables using an interface defined by an abstract class.  Instantiate concrete classes somewhere.  The creational patterns make the instantiation possible.  Abstract Factory, Builder, Factory Method, Prototype, Singleton.
  • 69. Putting Reuse Mechanisms to Work  Inheritance versus Composition  Delegation  Inheritance versus Parameterized Types
  • 70. Inheritance versus Composition  Inheritance is referred to as white-box reuse.  Object composition: assembling or composing objects to get more complex objects. referred as black-box reuse.
  • 71. Reuse by Inheritance  The advantages:  Defined statically at compile-time and is straightforward to use.  Easier to modify the implementation being reused.  Reuse by overrides some but not all operations.  The disadvantages:  Can not change the implementations at run-time.  Parent classes define part of the sub-classes’ physical representation. (inheritance breaks encapsulation)
  • 72. Reuse by Composition  Composition requires objects to respect each others’ interfaces. So we don’t break encapsulation.  Any object can be replaced at run-time by another as long as it has the same type.  Reduce the implementation dependencies.  The classes and class hierarchies will remain small.
  • 73. Favor object composition over class inheritance  You should be able to get all the functionality you need by assembling existing components.  You may use inheritance to define new components if the existing components are not enough.  Designs are often made more reusable by depending more on object composition.
  • 74. Delegation(1)  A way of making composition as powerful as inheritance.  A receiving object delegates operations to its delegate. Window Area() Rectangle Area() width height
  • 75. Delegation(2)  The advantage:  easy to compose behaviors at run-time  easy to change the way they’re composed.  Disadvantage:  Dynamic, highly parameterized software is harder to understand than static software.  run-time inefficiencies.  A good choice when it simplifiers more than it complicates.
  • 76. Delegation(3)  The design patterns using delegation:  State, Strategy, Visitor  Less heavily: Mediator, Chain of Responsibility, Bridge.
  • 77. Inheritance versus Parameterized Types  generics (Ada, Eiffel) or templates(C++)  A third way to reuse: Lets you define a type without specifying all the other types (as parameters) it uses.
  • 78. Compare the three reuse methods  Object composition lets you change the behavior being composed at run-time. It requires indirection and can be less efficient.  Inheritance lets you provide default implementation, and lets you override them.  Parameterized types let you change the types that a class can use.
  • 79. Relating Run-Time and Compile-Time Structures(1)  An object oriented program’s run-time structure often bears little resemblance to its code structure.
  • 80. Aggregation and Acquaintance  Aggregation: one object owns or is responsible for another object.  Acquaintance: an object merely knows of another object. (also called ‘association’ or ‘using’)  Aggregation and acquaintance are similar. They are determined more by intent than by language mechanisms.  They are significantly different at the run-time.
  • 81. Relating Run-Time and Compile-Time Structures(2)  We can not reveal everything about how a system will work.  The system’s run-time structure must be imposed more by designer.  Many design patterns capture the distinction between compile-time and run-time structures:  Composite, Decorator, Chain of Responsibility.
  • 82. Designing for Change  A design that doesn’t take change into account risks major redesign in the future.  Design patterns help you avoid this by ensuring that a system can change in specific ways.
  • 83. Common causes of redesign  Creating an object by specifying a class explicitly.  Abstract Factory, Factory Method, Prototype.  Dependence on specific operations:  Chain of Responsibility, Command.  Dependence on hardware and software platform  Chain of Responsibility, Command
  • 84. Common causes of redesign(2)  Dependence on object representations or implementations  Abstract Factory, Bridge, Memento, Proxy.  Algorithm dependencies  Builder, Iterator, Strategy, Template Method, Visitor.  Tight coupling  Abstract Factory, Bridge, Chain of Responsibility, Command, Facade, Mediator, Obser ver.
  • 85. Common causes of redesign(3)  Extending functionality by subclassing  Bridge, Chain of Responsibility, Composite, Decorator, Observer, Strategy.  Inability to alter conveniently  Adapter, Decorator, Visitor
  • 86. The flexibility for different kind of software  Application Programs  Toolkits  Frameworks
  • 87. Using design patterns for application programs  internal reuse, maintainability, and extension are high priorities.  Design patterns increase internal reuse by reduce the dependencies.  Design patterns make an application more maintainable when they’re used to limit platform dependencies and to layer a system.  Reduce coupling also enhances extensibility.
  • 88. Using design patterns for toolkits  Toolkits is a set of related and reusable classes designed to provide useful, general-purpose functionality.  Toolkits emphasize code reuse.  The designer should avoid assumptions and dependencies that can limit the toolkit’s flexibility.
  • 89. Using design patterns for frameworks  A framework is a set of cooperating classes that make up a reusable design design for a specific class of software.  A framework defines:  over-all structure  its partitioning into classes and objects.  key responsibilities thereof,  the way the objects collaborate, and the control.  A framework emphasize design reuse.
  • 90. Using design patterns for frameworks(2)  When you use a framework, you reuse the main body, and write the code it calls.  The software have the similar structure. They are easier to maintain.  Designing a frameworks is the hardest one.
  • 91. Using design patterns for frameworks(3)  The most critical issues for framewrok design:  As flexible and extensible as possible.  Loose coupling between the elements.  A framework using design patterns is far more likely to achieve high levels of design and code reuse than the one doesn’t.  Design patterns can enhance the documentation of the framework.
  • 92. Patterns vs Frameworks  Design patterns are more abstract than frameworks.  Design patterns are smaller architectural elements.  Design patterns are less specialized than framework.
  • 93. Patterns vs Frameworks  Patterns are lower-level than frameworks  Frameworks typically employ many patterns:  Factory  Strategy  Composite  Observer  Done well, patterns are the “plumbing” of a framework
  • 94. How to select a design pattern  Approaches to finding the design patterns:  Consider how design patterns solve design problems.  Scan intent sections.  Study how patterns interrelate.  Study patterns of like purpose.  Examine a cause of redesign.  Consider what should be variable in your design.(see table 1.2)
  • 95. Where They are Used  Object-Oriented programming languages [and paradigm] are more amenable to implementing design patterns  Procedural languages: need to define  Inheritance  Polymorphism  Encapsulation
  • 96. When to Use Patterns  Solutions to problems that recur with variations  No need for reuse if problem only arises in one context  Solutions that require several steps:  Not all problems need all steps  Patterns can be overkill if solution is a simple linear set of instructions  Solutions where the solver is more interested in the existence of the solution than its complete derivation  Patterns leave out too much to be useful to someone who really wants to understand  They can be a temporary bridge
  • 97. Suggestions for Effective Use  Do not recast everything as a pattern  Instead, develop strategic domain patterns and reuse existing tactical patterns  Institutionalize rewards for developing patterns  Directly involve pattern authors with application developers and domain experts  Clearly document when patterns apply and do not apply  Manage expectations carefully.
  • 98. How to use a design pattern  A step-by-step approach:  Read the pattern once through for an overview.  Go back and study the Structure, Participants, and Collaborations sections.  Look at the sample Code section to see a concrete example of the pattern in Code.  Choose names for pattern participants that are meaningful in the application context.
  • 99. How to use a design pattern(2)  Define the classes.  Define application-specific names for operations in the pattern.  Implement the operations to carry out the responsibilities and collaborations in the pattern.
  • 100. Benefits of Design Patterns  Design patterns enable large-scale reuse of software architectures and also help document systems  Patterns explicitly capture expert knowledge and design tradeoffs and make it more widely available  Patterns help improve developer communication  Pattern names form a common vocabulary  Patterns help ease the transition to OO technology
  • 101. 103 Benefits of Design Patterns  Enhance understanding, restructuring, & team communication  Basis for automation  Transcends language-centric biases/myopia  Abstracts away from many unimportant details
  • 102. Drawbacks to Design Patterns  Patterns do not lead to direct code reuse  Patterns are deceptively simple  Teams may suffer from pattern overload  Patterns are validated by experience and discussion rather than by automated testing  Integrating patterns into a software development process is a human-intensive activity.
  • 103. 105 Drawbacks to Design Patterns  Require significant tedious & error-prone human effort to handcraft pattern implementations design reuse  May limit design options  Leaves some important details unresolved
  • 104. Design Patterns are NOT  Designs that can be encoded in classes and reused as is (i.e., linked lists, hash tables)  Complex domain-specific designs (for an entire application or subsystem)  They are:  “Descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.”
  • 106. Exapmle: Model-View-Controller Pattern  MVC consists of three kinds of objects:  Model – the application object  View – UI (screen presentation)  Controller – defines the way the UI reacts to user inputs
  • 107. MVC – What Is the Problem?  The same enterprise data needs to be accessed when presented in different views: e.g. HTML, JFC/swing, XML  The same enterprise data needs to be updated through different interactions  Supporting multiple types of views and interactions should not impact the components that provide the core functionality of the enterprise application
  • 108. MVC – Solution  Separate core business model functionality from the presentation and control logic that uses this functionality  Allows multiple views to share the same enterprise data model  Makes supporting multiple clients easier to implement, test, and maintain
  • 110. MVC – Responsibilities  Model - the model represents enterprise data and the business rules that govern access to and updates of this data  View -the view renders the contents of a model. It accesses enterprise data through the model and specifies how that data should be presented  Controller - the controller translates interactions with the view into actions to be performed by the model
  • 111. MVC – Class Diagram
  • 112. MVC – Class Diagram Observer Pattern Strategy Pattern
  • 113. MVC – Class Diagram (including interfaces)
  • 114. MVC – Class Diagram (including interfaces) controller view model
  • 116. Design Patterns Observer Pattern  Define a one-to-many dependency, all the dependents are notified and updated automatically  The interaction is known as publish-subscribe or subscribe-notify  Avoiding observer-specific update protocol: pull model vs. push model  Other consequences and open issues
  • 117. Design Patterns Composite Pattern  View can be nested  Described by the Composite design pattern seen in the lecture
  • 118. Design Patterns Strategy Pattern – Class Diagram
  • 119. Design Patterns Strategy Pattern  Define family of algorithms, encapsulates them and make them interchangeable  Eliminate conditional statements  Cons: communication overhead, increase number of objects
  • 122. Example: Stock Quote Service Real time Market Data Feed Stock Quotes Customer Customer Customer Customer Customer Observers
  • 123. Observer Pattern  Intent:  Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically  Key forces:  There may be many observers  Each observer may react differently to the same notification  The subject should be as decoupled as possible from the observers to allow observers to change independently of the subject
  • 124. Structure of Observer Pattern +notify() +attach(in Observer) +detach(in Observer) Subject +getState() -subjectSate ConcreteSubject +update() Observer +update() ConcreteObserver 1 * 1 * return subjectState observerState = subject->getState() for all observers obs { obs->update() }
  • 125. Collaborations in Observer Pattern S1 : ConcreteSubject obs1 : ConcreteObserver obs2 : ConcreteObserver setState() notify() update() getState() update() getState()
  • 126. 128 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
  • 127. 129 OBSERVER object behavioral class ProxyPushConsumer : public // … virtual void push (const CORBA::Any &event) { for (std::vector<PushConsumer>::iterator i (consumers.begin ()); i != consumers.end (); i++) (*i).push (event); } CORBA Notification Service example using C++ Standard Template Library (STL) iterators (which is an example of the Iterator pattern from GoF) class MyPushConsumer : public // …. virtual void push (const CORBA::Any &event) { /* consume the event. */ }
  • 128. 130 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 Message Service)  Mailing lists
  • 129. Conclusions  Design Patterns provide a foundation for further understanding of:  Object-Oriented design  Software Architecture  Understanding patterns can take some time  Re-reading them over time helps  As does applying them in your own designs!