Presentation

Object Relations and
Syntactic Mechanisms in
Design Patterns
Uriel Cohen
Introduction
!
!
Q: How can we capture design
knowledge in software engineering?
A: Design patterns
#include <iostream.h>
int main()
!
Elements of a
design pattern:
!
!
!
!
name
problem
solution
consequences
{
int i;
DESIGN
PATTERN
...
for (i=0;i<10;i++)
cout << i;
...
...
return 0;
}
Design Patterns
!
Advantages:
!
!
!
!
Common language
Higher level of abstraction
Code-reusability
Problems:
!
!
!
Traceability problem
Reusability problem
Implementation overhead
Motivation of the Research
!
Design patterns as lingual features.
!
Bosch, 1998 – LayOM.
Agerbo and Cornils, 1998 – class library of
Fundamental Design Patterns in BETA.
Chambers, Harrison and Vlissides, POPL 2000 –
A debate on language and tool support for design
patterns.
!
!
Course of Action
1.
2.
Data set of design patterns.
Investigate:
!
!
3.
Syntactic mechanisms in design patterns.
Objects relations in design patterns.
Propose useful lingual features.
Our Taxonomy of Patterns
Patterns
Domain Specific
(Algorithmic)
!
!
!
General Purpose
(Programmatic)
A lot of research involved.
Differentiates between patterns
and design patterns.
Allows us to select a data set of patterns.
Source of DPs: Tichy, 1997
Our Taxonomy of Patterns
Patterns
28 patterns
Domain Specific
(Algorithmic)
Source of DPs: Tichy, 1997
General Purpose
(Programmatic)
Our Taxonomy of Patterns
Patterns
28 patterns
Domain Specific
(Algorithmic)
Concurrency
General Purpose
(Programmatic)
17 patterns
Distribution
9 patterns
Virtual
Machines
2 patterns
Source of DPs: Tichy, 1997
Our Taxonomy of Patterns
Patterns
28 patterns
Domain Specific
(Algorithmic)
Concurrency
Distribution
Virtual
Machines
Source of DPs: Tichy, 1997
General Purpose
(Programmatic)
67 patterns
Our Taxonomy of Patterns
Patterns
28 patterns
Domain Specific
(Algorithmic)
Concurrency
Distribution
General Purpose
(Programmatic)
67 patterns
Sentence
Level
Module Level
Architectural
Level
7 patterns
54 patterns
6 patterns
Virtual
Machines
Source of DPs: Tichy, 1997
Our Taxonomy of Patterns
Patterns
28 patterns
Domain Specific
(Algorithmic)
Concurrency
General Purpose
(Programmatic)
Sentence
Level
Distribution
Virtual
Machines
Source of DPs: Tichy, 1997
Module Level
67 patterns
Architectural
Level
Our Taxonomy of Patterns
Patterns
28 patterns
Domain Specific
(Algorithmic)
Concurrency
General Purpose
(Programmatic)
Sentence
Level
Distribution
Virtual
Machines
Source of DPs: Tichy, 1997
Module Level
Cliches
4 patterns
Idioms
3 patterns
67 patterns
Architectural
Level
Our Taxonomy of Patterns
Patterns
28 patterns
Domain Specific
(Algorithmic)
Concurrency
General Purpose
(Programmatic)
Sentence
Level
Distribution
Virtual
Machines
Source of DPs: Tichy, 1997
Module Level
Cliches
Idioms
67 patterns
Architectural
Level
Our Taxonomy of Patterns
Patterns
28 patterns
Domain Specific
(Algorithmic)
Concurrency
General Purpose
(Programmatic)
Sentence
Level
Distribution
Virtual
Machines
67 patterns
Architectural
Level
Module Level
Cliches
Procedural
Patterns
10 patterns
Idioms
Design
Patterns
29 patterns
Variations
12 patterns
Compound
Patterns
3 patterns
Source of DPs: Tichy, 1997
Our Taxonomy of Patterns
Patterns
28 patterns
Domain Specific
(Algorithmic)
Concurrency
General Purpose
(Programmatic)
Sentence
Level
Distribution
Virtual
Machines
67 patterns
Architectural
Level
Module Level
Cliches
Procedural
Patterns
Idioms
Design
Patterns
Variations
Source of DPs: Tichy, 1997
Compound
Patterns
Our Taxonomy of Patterns
Patterns
28 patterns
Domain Specific
(Algorithmic)
Concurrency
General Purpose
(Programmatic)
Sentence
Level
Distribution
Virtual
Machines
67 patterns
Architectural
Level
Module Level
Cliches
Procedural
Patterns
Idioms
Design
Patterns
Variations
Source of DPs: Tichy, 1997
Compound
Patterns
Architectural
Patterns
6 patterns
Design Patterns Data Set
Patterns
Domain Specific
(Algorithmic)
Concurrency
General Purpose
(Programmatic)
Sentence
Level
Distribution
Virtual
Machines
Architectural
Level
Module Level
Cliches
Procedural
Patterns
Idioms
Design
Patterns
Variations
Source of DPs: Tichy, 1997
Compound
Patterns
Architectural
Patterns
Design Patterns in the Data Set
!
!
GoF patterns
!
!
Prototype
Singleton
Gamma, 1998
!
!
Extension Objects
Facade
Flyweight
Proxy
Behavioral
Chain of Responsibility
Command
Interpreter
Iterator
Mediator
Extension Objects
Manager
Sommerlad, 1998
Structural
Adapter
Bridge
Composite
Decorator
!
!
Creational
Abstract Factory
Builder
Factory Method
Additional patterns
Vermeulen, Beged-Dov and
Thompson, 1995
!
Product Trader
Baumer and Riehle, 1998
!
Memento
Observer
State
Strategy
Visitor
Pipeline
Sponsor-Selector
Wallingford, 1998
!
Type Object
Johnson and Woolf, 1998
Composition
Structure of the composition
Owner
OwnerMethod()
component
component
Component
CmpMethod()
Composition vs. Inheritance
!
!
!
Inheritance
Big class hierarchies.
Break of
encapsulation.
Binds at compile
time.
!
!
!
Composition
Hard to understand.
Not enough existing
components.
Binds at run-time.
Composition and inheritance should be
used in combination.
Composition in Design Patterns
!
No inheritance:
Composition:
Adapter (class)
Factory Method
Template Method
Singleton
[rest of the DPs]
!
Interfaces:
[most DPs]
!
!
!
Inheritance:
Abstract base class:
Implementing Composition
!
!
!
!
!
!
Implementation Criteria Set
Coupling strength
Time of coupling
Features export
Overriding prior to export
Internal dynamic binding
External dynamic binding
Criteria suggested by Gil and Lorenz, 1997.
Example – PROXY pattern
Client
Subject
Request()
LazyRequest()
...
realSubject
RealSubject
Proxy
Request()
...
Request()
LazyRequest()
...
realSubject->Request()
...
realSubject->Request()
...
!
Purpose: placeholder for another object.
Coupling Strength
“How strong is the connection between the
participants of the composition?”
Attribute
!
!
!
!
reference or value ?
references or pointers ?
exclusive or shared ?
single or list of objects ?
PROXY pattern
!
!
!
!
reference semantics.
use of pointers.
shared component.
single component.
Exporting and Overriding Features
“Is the connection exported?”
“May the connection be overridden before it is
exported?”
PROXY pattern:
Features
Name
Request()
LazyRequest()
Overriding
Number
none
group
√
group
replace ✍-refine
√
√
Conclusions
!
Gained insight of:
!
!
!
Syntactic mechanisms found in design
patterns.
Language features useful to implement design
patterns.
Future of mainstream OOP languages.
Proposed Lingual Construct
!
!
Connectors
Ducasse and Richner, 1997 –
FLO model in CLOS and SMALLTALK.
Additional Requirements:
!
!
!
Type checking of components
Method refinement
Substitution of the component