SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
Selected Design Patterns
Prof. Dr. Ralf Lämmel
Universität Koblenz-Landau
Software Languages Team
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Reusable solutions to
recurrent problems
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Selected patterns
(Pattern names with intents)
Composite -- provide uniform interface on part-whole hierarchies
Command -- encapsulate the execution of functionality; enable undo
Visitor -- represent operations on object structure as objects
Observer -- provide change notifications to objects depending on state
MVC -- decouple model, view, control in for interactive applications
Proxy -- refine or replace behavior of a given object
Object Adapter -- provide a different interface for an existing object
Template Method -- capture general structure of an algorithm
...
Intent = short combo
of problem + solution
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Observer -- Problem
The observer pattern (aka publish/subscribe) involves
an object, called the subject, which maintains a list of
its dependents, called observers, and notifies them
automatically of any state changes.
Do you know the problem?
Do you know a solution?
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Observer -- Solution
http://en.wikipedia.org/wiki/File:Observer.svg
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Essential elements of a
design pattern
Name
The problem describes when to apply the pattern.
The solution describes elements of the design, their
relationships, responsibilities, and collaborations.
The consequences are the results and trade-offs of
applying the pattern.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Describing design patterns
Pattern Name
Classification
Intent
Also Known As
Motivation
Applicability
Structure
Participants
Collaborations
Consequences
Implementation
Sample Code
Known Uses
Related Patterns
We do
not go into all
these details in this
course.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Classification of
design patterns
Aspects
Creational patterns
Structural patterns
Behavioral patterns
Scope
Class
Object
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Design patterns -- Overview
[Gamma et al., 1995, S. 10]
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Design patterns
of this slide deck
Template Method
Abstract Factory
Object Adapter
Observer
Proxy
You are definitely
expected to expand on
your knowledge of
design patterns.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Abstract Factory -- Problem
Object models often give rise to variation. For instance,
there may be multiple GUI libraries subject to different
widget hierarchies. Whenever components want to
abstract from the specific choice, then substantial efforts
are required. For instance, the construction of objects
must be tunneled through a factory.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Abstract Factory -- Solution
http://sourcemaking.com/design_patterns/abstract_factory
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Abstract Factory
DEMO
Two alternative object models for companies.
POJOs
Some sort of beans
Make the choice of the object model configurable.
Contribution:javaExorcism
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Proxy -- Problem
Additional access behavior for objects
Access management for remote objects
Access management for expensive objects
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Proxy -- Solution
http://en.wikipedia.org/wiki/File:Proxy_pattern_diagram.svg
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Proxy -- Scenarios
Additional access behavior for objects
Access management for remote objects
Access management for expensive objects
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Proxy
DEMO
Use security proxy to protect salary access.
Interesting issue of proxy deployment.
Contribution:javaExorcism
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Observer -- Problem
The observer pattern (aka publish/subscribe) involves
an object, called the subject, which maintains a list of
its dependents, called observers, and notifies them
automatically of any state changes.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Observer -- Solution
http://en.wikipedia.org/wiki/File:Observer.svg
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Observer
DEMO
Use observer to providing logging.
Use observer to enforce data constraint.
Contribution:javaExorcism
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Object Adapter -- Problem
A given object often has about the right capabilities for a
specific client but not necessarily the precise interface
expected. Accordingly, an interface adaptation can be
achieved by an extra wrapper around the given object.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Adapter -- Solution
(object adapters)
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Adapter -- Solution
(class adapters)
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Adapter
DEMO
Class adapter: add observability of list interface.
Object adapter: downgrade java.util.List to simple list.
Contribution:javaExorcism
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Template Method -- Problem
Some algorithms or strategies in a system may be very
similar and hence it may be desirable to capture their
commonalities in a sort of template so that specifics can
be expressed through refinement giving rise to a high
degree of reuse.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Template Method -- Solution
http://stephane.ducasse.free.fr/FreeBooks/SmalltalkDesignPatternCompanion/templateMethod.pdf
Intent
Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Temp
Method lets subclasses redefine certain steps of an algorithm without changing the algorith
structure.
Structure
Description
Template Method may be #1 on the Design Patterns Pop Charts. Its structure and use are at the h
of much of object-oriented programming. Template Method turns on the fundamental object-orie
templateMethod
AbstractClass
ConcreteClassA
primitiveMethod2
primitiveMethod1
primitiveMethod1
primitiveMethod2
...
self primitiveMethod1.
...
self primitiveMethod2.
...
ConcreteClassB
primitiveMethod1
primitiveMethod2
ConcreteClassC
primitiveMethod2
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Template
DEMO
Two general class of algorithms can identified:
Queries such as 101feature:Total
Transformations such as 101feature:Cut
Contribution:javaTemplate
Contribution:javaExorcism
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Summary
The use of design patterns is a basic element of software
development. If you wouldn’t use them, your designs
and implementations are unnecessarily unstandardized,
idiosyncratic, incomprehensible, unmaintainable, etc.
That is, if you are interested in a software development
career, or you plan to talk to software developers at an
interesting level of detail, you have to aggregate
substantial knowledge of design patterns.

Weitere ähnliche Inhalte

Was ist angesagt? (7)

Interoperability of Meta-Modeling Tools
Interoperability of Meta-Modeling ToolsInteroperability of Meta-Modeling Tools
Interoperability of Meta-Modeling Tools
 
Topic 1 PBO
Topic 1 PBOTopic 1 PBO
Topic 1 PBO
 
LDAC 2015 - Towards an industry-wide ifcOWL: choices and issues
LDAC 2015 - Towards an industry-wide ifcOWL: choices and issuesLDAC 2015 - Towards an industry-wide ifcOWL: choices and issues
LDAC 2015 - Towards an industry-wide ifcOWL: choices and issues
 
Generative programming (mostly parser generation)
Generative programming (mostly parser generation)Generative programming (mostly parser generation)
Generative programming (mostly parser generation)
 
Matlab OOP
Matlab OOPMatlab OOP
Matlab OOP
 
Model Comparison for Delta-Compression
Model Comparison for Delta-CompressionModel Comparison for Delta-Compression
Model Comparison for Delta-Compression
 
Generation of Random EMF Models for Benchmarks
Generation of Random EMF Models for BenchmarksGeneration of Random EMF Models for Benchmarks
Generation of Random EMF Models for Benchmarks
 

Andere mochten auch (12)

Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013
Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013
Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013
 
XML data binding
XML data bindingXML data binding
XML data binding
 
Fotos De Santa Catarina
Fotos De Santa CatarinaFotos De Santa Catarina
Fotos De Santa Catarina
 
C004 60190 02238 1 Roberts Stuart
C004 60190 02238 1 Roberts StuartC004 60190 02238 1 Roberts Stuart
C004 60190 02238 1 Roberts Stuart
 
Grey Food Trends - Recession and "Credit Crunch Cuisine"
Grey Food Trends - Recession and "Credit Crunch Cuisine"Grey Food Trends - Recession and "Credit Crunch Cuisine"
Grey Food Trends - Recession and "Credit Crunch Cuisine"
 
Ec305.13 buses mgl
Ec305.13 buses mglEc305.13 buses mgl
Ec305.13 buses mgl
 
Functional data structures
Functional data structuresFunctional data structures
Functional data structures
 
Remote method invocation (as part of the the PTT lecture)
Remote method invocation (as part of the the PTT lecture)Remote method invocation (as part of the the PTT lecture)
Remote method invocation (as part of the the PTT lecture)
 
Ramadan For Bodyand Soul
Ramadan For Bodyand SoulRamadan For Bodyand Soul
Ramadan For Bodyand Soul
 
Do U Know Him
Do U Know HimDo U Know Him
Do U Know Him
 
Human Generation
Human GenerationHuman Generation
Human Generation
 
Modeling software systems at a macroscopic scale
Modeling software systems  at a macroscopic scaleModeling software systems  at a macroscopic scale
Modeling software systems at a macroscopic scale
 

Ähnlich wie Selected design patterns (as part of the the PTT lecture)

Metaprograms and metadata (as part of the the PTT lecture)
Metaprograms and metadata (as part of the the PTT lecture)Metaprograms and metadata (as part of the the PTT lecture)
Metaprograms and metadata (as part of the the PTT lecture)
Ralf Laemmel
 
Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)
Ralf Laemmel
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 
Functional OO programming (as part of the the PTT lecture)
Functional OO programming (as part of the the PTT lecture)Functional OO programming (as part of the the PTT lecture)
Functional OO programming (as part of the the PTT lecture)
Ralf Laemmel
 
Writting Better Software
Writting Better SoftwareWritting Better Software
Writting Better Software
svilen.ivanov
 
Database programming including O/R mapping (as part of the the PTT lecture)
Database programming including O/R mapping (as part of the the PTT lecture)Database programming including O/R mapping (as part of the the PTT lecture)
Database programming including O/R mapping (as part of the the PTT lecture)
Ralf Laemmel
 
Full resume dr_russell_john_childs_2016
Full resume dr_russell_john_childs_2016Full resume dr_russell_john_childs_2016
Full resume dr_russell_john_childs_2016
Russell Childs
 
Full_resume_Dr_Russell_John_Childs
Full_resume_Dr_Russell_John_ChildsFull_resume_Dr_Russell_John_Childs
Full_resume_Dr_Russell_John_Childs
Russell Childs
 

Ähnlich wie Selected design patterns (as part of the the PTT lecture) (20)

Metaprograms and metadata (as part of the the PTT lecture)
Metaprograms and metadata (as part of the the PTT lecture)Metaprograms and metadata (as part of the the PTT lecture)
Metaprograms and metadata (as part of the the PTT lecture)
 
Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)
 
L03 Design Patterns
L03 Design PatternsL03 Design Patterns
L03 Design Patterns
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Functional OO programming (as part of the the PTT lecture)
Functional OO programming (as part of the the PTT lecture)Functional OO programming (as part of the the PTT lecture)
Functional OO programming (as part of the the PTT lecture)
 
Day1
Day1Day1
Day1
 
Writting Better Software
Writting Better SoftwareWritting Better Software
Writting Better Software
 
DRESD Project Presentation - December 2006
DRESD Project Presentation - December 2006DRESD Project Presentation - December 2006
DRESD Project Presentation - December 2006
 
MODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSE
MODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSEMODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSE
MODEL DRIVEN ARCHITECTURE, CONTROL SYSTEMS AND ECLIPSE
 
A Program Transformation Technique to Support Aspect-Oriented Programming wit...
A Program Transformation Technique to Support Aspect-Oriented Programming wit...A Program Transformation Technique to Support Aspect-Oriented Programming wit...
A Program Transformation Technique to Support Aspect-Oriented Programming wit...
 
Database programming including O/R mapping (as part of the the PTT lecture)
Database programming including O/R mapping (as part of the the PTT lecture)Database programming including O/R mapping (as part of the the PTT lecture)
Database programming including O/R mapping (as part of the the PTT lecture)
 
Full resume dr_russell_john_childs_2016
Full resume dr_russell_john_childs_2016Full resume dr_russell_john_childs_2016
Full resume dr_russell_john_childs_2016
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
MoDisco & ATL - Eclipse DemoCamp Indigo 2011 in Nantes
MoDisco & ATL - Eclipse DemoCamp Indigo 2011 in NantesMoDisco & ATL - Eclipse DemoCamp Indigo 2011 in Nantes
MoDisco & ATL - Eclipse DemoCamp Indigo 2011 in Nantes
 
Full_resume_Dr_Russell_John_Childs
Full_resume_Dr_Russell_John_ChildsFull_resume_Dr_Russell_John_Childs
Full_resume_Dr_Russell_John_Childs
 
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
 
Object oriented design-UNIT V
Object oriented design-UNIT VObject oriented design-UNIT V
Object oriented design-UNIT V
 
Ase02 dmp.ppt
Ase02 dmp.pptAse02 dmp.ppt
Ase02 dmp.ppt
 
Extending Rotor with Structural Reflection to support Reflective Languages
Extending Rotor with Structural Reflection to support Reflective LanguagesExtending Rotor with Structural Reflection to support Reflective Languages
Extending Rotor with Structural Reflection to support Reflective Languages
 
ALT
ALTALT
ALT
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Selected design patterns (as part of the the PTT lecture)

  • 1. Selected Design Patterns Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages Team
  • 2. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Reusable solutions to recurrent problems
  • 3. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Selected patterns (Pattern names with intents) Composite -- provide uniform interface on part-whole hierarchies Command -- encapsulate the execution of functionality; enable undo Visitor -- represent operations on object structure as objects Observer -- provide change notifications to objects depending on state MVC -- decouple model, view, control in for interactive applications Proxy -- refine or replace behavior of a given object Object Adapter -- provide a different interface for an existing object Template Method -- capture general structure of an algorithm ... Intent = short combo of problem + solution
  • 4. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Observer -- Problem The observer pattern (aka publish/subscribe) involves an object, called the subject, which maintains a list of its dependents, called observers, and notifies them automatically of any state changes. Do you know the problem? Do you know a solution?
  • 5. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Observer -- Solution http://en.wikipedia.org/wiki/File:Observer.svg
  • 6. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Essential elements of a design pattern Name The problem describes when to apply the pattern. The solution describes elements of the design, their relationships, responsibilities, and collaborations. The consequences are the results and trade-offs of applying the pattern.
  • 7. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Describing design patterns Pattern Name Classification Intent Also Known As Motivation Applicability Structure Participants Collaborations Consequences Implementation Sample Code Known Uses Related Patterns We do not go into all these details in this course.
  • 8. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Classification of design patterns Aspects Creational patterns Structural patterns Behavioral patterns Scope Class Object
  • 9. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Design patterns -- Overview [Gamma et al., 1995, S. 10]
  • 10. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Design patterns of this slide deck Template Method Abstract Factory Object Adapter Observer Proxy You are definitely expected to expand on your knowledge of design patterns.
  • 11. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Abstract Factory -- Problem Object models often give rise to variation. For instance, there may be multiple GUI libraries subject to different widget hierarchies. Whenever components want to abstract from the specific choice, then substantial efforts are required. For instance, the construction of objects must be tunneled through a factory.
  • 12. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Abstract Factory -- Solution http://sourcemaking.com/design_patterns/abstract_factory
  • 13. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Abstract Factory DEMO Two alternative object models for companies. POJOs Some sort of beans Make the choice of the object model configurable. Contribution:javaExorcism
  • 14. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Proxy -- Problem Additional access behavior for objects Access management for remote objects Access management for expensive objects
  • 15. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Proxy -- Solution http://en.wikipedia.org/wiki/File:Proxy_pattern_diagram.svg
  • 16. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Proxy -- Scenarios Additional access behavior for objects Access management for remote objects Access management for expensive objects
  • 17. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Proxy DEMO Use security proxy to protect salary access. Interesting issue of proxy deployment. Contribution:javaExorcism
  • 18. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Observer -- Problem The observer pattern (aka publish/subscribe) involves an object, called the subject, which maintains a list of its dependents, called observers, and notifies them automatically of any state changes.
  • 19. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Observer -- Solution http://en.wikipedia.org/wiki/File:Observer.svg
  • 20. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Observer DEMO Use observer to providing logging. Use observer to enforce data constraint. Contribution:javaExorcism
  • 21. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Object Adapter -- Problem A given object often has about the right capabilities for a specific client but not necessarily the precise interface expected. Accordingly, an interface adaptation can be achieved by an extra wrapper around the given object.
  • 22. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Adapter -- Solution (object adapters)
  • 23. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Adapter -- Solution (class adapters)
  • 24. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Adapter DEMO Class adapter: add observability of list interface. Object adapter: downgrade java.util.List to simple list. Contribution:javaExorcism
  • 25. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Template Method -- Problem Some algorithms or strategies in a system may be very similar and hence it may be desirable to capture their commonalities in a sort of template so that specifics can be expressed through refinement giving rise to a high degree of reuse.
  • 26. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Template Method -- Solution http://stephane.ducasse.free.fr/FreeBooks/SmalltalkDesignPatternCompanion/templateMethod.pdf Intent Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Temp Method lets subclasses redefine certain steps of an algorithm without changing the algorith structure. Structure Description Template Method may be #1 on the Design Patterns Pop Charts. Its structure and use are at the h of much of object-oriented programming. Template Method turns on the fundamental object-orie templateMethod AbstractClass ConcreteClassA primitiveMethod2 primitiveMethod1 primitiveMethod1 primitiveMethod2 ... self primitiveMethod1. ... self primitiveMethod2. ... ConcreteClassB primitiveMethod1 primitiveMethod2 ConcreteClassC primitiveMethod2
  • 27. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Template DEMO Two general class of algorithms can identified: Queries such as 101feature:Total Transformations such as 101feature:Cut Contribution:javaTemplate Contribution:javaExorcism
  • 28. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Summary The use of design patterns is a basic element of software development. If you wouldn’t use them, your designs and implementations are unnecessarily unstandardized, idiosyncratic, incomprehensible, unmaintainable, etc. That is, if you are interested in a software development career, or you plan to talk to software developers at an interesting level of detail, you have to aggregate substantial knowledge of design patterns.