Professional Documents
Culture Documents
Lecture 02 PDF
Lecture 02 PDF
“Each pattern describes a problem that 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”
History
● Christopher Alexander proposes patterns as a way of capturing design
knowledge in architecture domain (1977 - 1979)
○ Each pattern represent a tried, efficient solution to a design problem
○ The Timeless Way of Building book, published in 1979
● Kent Beck & Ward Cunningham used Alexander’s design patterns ideas for
smalltalk GUI design
○ OOPSLA workshop (Object-Oriented Programming, Systems, Languages, and Applications),
1987
● Erich Gamma, Richard Helm, Ralf Johnson, and John Vlissides
○ Design Patterns: Elements of Reusable Object-Oriented Software book, 1994
○ Known as Gang of Four - GoF
Patterns in Software
● “…a pattern is a named problem/solution pair that can be applied in new
contexts, with advice on how to apply it and discussion of its trade-offs.” *
● Applicability
○ Situations/ circumstances in which the pattern can be applied
● Structure
○ A graphical representation of the classes involved in the pattern
● Participants
○ Classes and objects participating in the pattern and their responsibilities
● Collaboration
○ Shows how participants cooperate to achieve their responsibilities
Cont… Pattern Description Template
● Consequences
○ Results of the application, benefits, costs
● Implementation
○ Specifies which techniques to be aware of when implementing the pattern, language issue,
dependencies
● Sample code
○ Code snippet/fragment which shows how to implement the pattern
● Known uses
○ Real examples in which the pattern were used
● Related patterns
○ Specify other patterns that relate to this pattern, and what are the differences between them
Catalog of Design Patterns
● There are multiple design patterns
○ So we need a way to classify them into families
● Classification patterns will help
○ Learning patterns faster
○ Finding new patterns
● Two criterias for classifying patterns
○ Based on the purpose
■ Reflects what the pattern does
○ Based on scope
■ Specifies whether the pattern applies to classes or objects
Types of Design Patterns (purpose)
● Based on the purpose, patterns are classified into three groups
○ Creational patterns
■ To create objects of the right class for the problem, generally when instances of several
different classes are available
○ Structural patterns
■ To form a larger structure from individual parts
○ Behavioral patterns
■ Describe interaction between objects
■ Focus on how parts communicate with other
Types of Design Patterns (scope)
● Class patterns
○ deals with relationships between classes and their subclasses
○ These relationships are established through inheritance
● Objects patterns
○ Deals with relationships between objects
Why Design Patterns
● Reuse tried, proven solutions
● Establish common vocabulary
○ Higher level of communication
○ Increase productivity
○ Save time to discuss details
○ Avoids misunderstandings