SlideShare a Scribd company logo
1 of 53
Download to read offline
Design Patterns
  illustrated




        Herman Peeren          May 31st 2010
              (DP-illustrations: Nelleke Verhoeff)
Design Patterns
●●   recipes against common (OO-) programming problems
●●   code reuse: no need to reinvent the wheel
●●   common language
●●   GOF: 23 “classical” patterns



                     classic,
                     The Book




                           very nice!
The one constant in software development:
The one constant in software development:



CHANGE!
The one constant in software development:



CHANGE!

                     I knew it ...
Ideal: code as modular black boxes
Wish list and OOP-principles
●●   loose coupling: 1 change = ceteris paribus

●●   code reuse (is not the same as copy/paste)

●●   open for extension, closed for modification

●●   encapsulate what varies

●●   single responsibility principle

●●   program against an interface not against an imple-
     mentation. Dependency injection

●●   prefer composition over inheritance

(in fact this is all the same with different words)
Avoid: tight coupling!
It might get you into trouble...
Beware of:



Code
smells!
some code smells:
1.●   duplicate code: DRY
2.●   long method, huge class: SRP
3.●   combinatorial explosion (similar classes)
4.●   conditional complexity, switch statements
5.●   “exhibitionistic” classes
some code smells:
1.●   duplicate code: DRY
2.●   long method, huge class: SRP
3.●   combinatorial explosion (similar classes)
4.●   conditional complexity, switch statements
5.●   “exhibitionistic” classes
Classic pattern categories
creational, structural and behavioral patterns:

●●   creational: object instantiation
●●   structural: larger structures of classes or objects
●●   behavioral: interaction and distribution of responsibility
Creational design patterns
●● Factory Method: Allow subclasses to “decide”
   which class to instantiate.
●● Abstract Factory: Encapsulate a set of analo-
   gous factories that produce families of objects.
●● Builder: Encapsulate the construction of com-
   plex objects from their representation; so, the
   same building process can create various repre-
   sentations by specifying only type and content.
●● Singleton: Ensure that only a single instance of
   a class exists and provide a single method for
   gaining access to it.
●● Prototype: Create an initialized instance for
   cloning or copying.
Factory Method
    Provide an interface for the creation of objects.
    Allow subclasses to “decide” which class to instantiate.
c
Abstract Factory
    Povide an interface for creating families of related
    or dependent objects. A factory for factories.
c
Builder
    Seperate the construction process (how) of a complex object
    from the concrete representations (what).
c
Singleton
    Ensure a class only has one instance, and provide a global
    point of access to it.




                               Oh, I’m so
                                loooooooonly
c
Joomla!
●●   JFactory: a class with static methods to instantiate objects
     like JDatabase, JUser, JDocument, JTemplate, etc.
●●   most of those methods are singletons




Nooku
●●   KFactory: any class can be instantiated
●●   get() = singleton, tmp() = any instantiation
“Every
      advantage
        has its
   disadvantages”
(free to Johan Cruyff,
Dutch Football Pattern Designer
and Ajax-fan...)
Prototype
    Make variations on copies of a basic-object.




                              COPY-SERVICE
c
Structural design patterns
●● Adapter: Adapt an interface to an expected
   interface.
●● Bridge: Decouple an interface from its
   implementation.
●● Composite: Create a tree structure for
   part-whole hierarchies.
●● Decorator: Extend functionality dynamically.
●● Facade: Simplify usage by defining a high-level
   interface.
●● Flyweight: Support fine-grained objects
   efficiently by sharing.
●● Proxy: Represent an object with another object
   for access control.
Adapter (= Wrapper)
c   Adapt an interface to an expected interface.
Joomla!
●●   new in 1.6: JAdapter and JAdapterInstance

●●   JUpdateAdapter extends JAdapterInstance

     JUpdaterExtension & JUpdaterExtension
     extend JUpdateAdapter


wanted: documentation and examples!
what does it adapt?
Bridge
    Decouple an abstraction from its implementation.




                                                                COLA
    1 LITER                                                     1 LITER

                                                      COLA
              1 LITER                                 1 LITER
                                               COLA
                        MILK

                                             COLA
                               MILK                 COLA
                   MILK
c
Composite
    Create a tree structure for part-whole hierarchies. A node is also a
    (part of a) tree. Recursive:
c
Decorator
    Add extra functionallity (at runtime),
    while keeping the interface the same.
    Matroushka’s...
c
Decorator




Nooku
●●   KPatternDecorator: a general decorator
●●   e.g. extended by KDecoratorJoomlaApplication
Facade
    Provide a general (simpler) interface for a set of interfaces.




              looks
             simple
c
Flyweight
    Use one instance of a class to provide many
    “virtual” instances.
c
Proxy
    Provide a surrogate or placeholder for another object
    to control access to it.
c
Behavioral design patterns
●● Chain of Responsibility: Define a method of passing a
request among a chain of objects.
●● Command: Encapsulate a command request in an object.
●● Interpreter: Allow inclusion of language elements in an appli-
cation.
●● Iterator: Enable sequential access to collection elements.
●● Mediator: Define simplified communication between classes.
●● Memento: Save and restore the internal state of an object.
●● Observer: Define a scheme for notifying objects of changes to
another object.
●● State: Alter the behavior of an object when its state changes.
●● Strategy: Encapsulate an algorithm inside a class.
●● Template Method: Allow subclasses to redefine the steps of
an algorithm.
●● Visitor: Define a new operation on a class without changing it.
Command
    Encapsulate a command request in an object.




                      YOU,DO YOUR
                         TASK!




          TASK                                    TASK
          LIGHT                                   LIGHT
           ON                                      OFF
c
Chain of Responsibility
c
    Define a method of passing a request among a chain of objects.
Nooku
●●   KCommandChain
     + KCommandContext, KCommandEvent, KCommandHandler and
     KCommandInterface

●●    N.B.: executes a series of commands
     instead of passing a command to a series of handlers
     (like in Tapestry e.g.) ...correct me if I’m wrong....
Interpreter
    Domain -> (little) language -> grammar -> objects
    (DSL)



              HÉ!         he means:
                      do this, do that,
                    and after finishing it,
                          go there!
c
Iterator
    Enable sequential access to collection elements, without showing
    the underlying data-structures (array, list, records, etc)


           next




    next
c
Mediator
c   Layer in between: communication via one object.
Memento
    Save and restore the internal state of an object.




                                          ME
c
Observer
    Notify “subscribers” of changes.



                                            ME

                                                 NO   ME
                                       ME


                 WHO?
c
Joomla!
●●   JObserver and JObservable
●●   JObserver extended by JEvent and that by JPlugin




Nooku
●●   KPatternObserver and KPatternObservable
State
Let an object show other methods after a change of internal
state (as if it changes it’s class).



      in a.....hick......different state,
      ....hick....I behave differently....hick.....




c
Strategy
    When something can be done in several ways, make those
    ways interchangeable.




                       POSSI-
                       BILITIES
c
Template Method
    The skeleton of an algorithm is fixed, but parts can be filled in
    differently.
c
Visitor
    Make a kind of plugin-possibility for methods: in that way me-
    thods can be added in runtime.




          printservice!
c
extra: Mixin
●●   Used in Nooku (and a.o. in Ruby and Python)
●●   a kind of abstract class that is mixed into another object
●●   all methods of the mixin are now part of the object
●●   handle with care: beware of tight coupling....
Golden OO-principles

 ●●   encapsulate what varies, OCP

 ●●   1class, 1 responsibility, SRP

 ●●   program against an interface, not against an imple-
      mentation, DIP

 ●●   prefer composition over inheritance

 ●●   loose coupling, modular black boxes
Some books
GOF: 23 “classical” patterns:




                               very nice!


                    classic,
                    The Book




                               handy
                               examples
good start




       Fowler:
       extended
       e.g. with
       patterns
       for web



Fowler: also
known from
refactoring




        combi: re-
        factoring
        & patterns
Resign Patterns:
Ailments of Unsuitable Project-Disoriented Software
Joomla!
Could be improved by studying design patterns and applying
them.

                                           Loose coupling...
Questions?



Contact info:
Herman Peeren
herman@yepr.nl
© Yepr
The artwork in this presentation is provided under the
Creative Commons Public License for noncommercial use.
http://creativecommons.org/licenses/by-nc/3.0/legalcode

More Related Content

What's hot

Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General IntroductionAsma CHERIF
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
 
Software design patterns ppt
Software design patterns pptSoftware design patterns ppt
Software design patterns pptmkruthika
 
Common language runtime clr
Common language runtime clrCommon language runtime clr
Common language runtime clrSanSan149
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patternsAmit Kabra
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net frameworkArun Prasad
 
Dependency injection presentation
Dependency injection presentationDependency injection presentation
Dependency injection presentationAhasanul Kalam Akib
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewShahed Chowdhuri
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonJonathan Simon
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern PresentationJAINIK PATEL
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion PrincipleShahriar Hyder
 
Entity Framework Core
Entity Framework CoreEntity Framework Core
Entity Framework CoreKiran Shahi
 

What's hot (20)

Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Design patterns in PHP
Design patterns in PHPDesign patterns in PHP
Design patterns in PHP
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Software design patterns ppt
Software design patterns pptSoftware design patterns ppt
Software design patterns ppt
 
LINQ in C#
LINQ in C#LINQ in C#
LINQ in C#
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Common language runtime clr
Common language runtime clrCommon language runtime clr
Common language runtime clr
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net framework
 
Dependency injection presentation
Dependency injection presentationDependency injection presentation
Dependency injection presentation
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design Pattern
 
Decorator Pattern
Decorator PatternDecorator Pattern
Decorator Pattern
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion Principle
 
Prototype_pattern
Prototype_patternPrototype_pattern
Prototype_pattern
 
Entity Framework Core
Entity Framework CoreEntity Framework Core
Entity Framework Core
 

Viewers also liked

Design Patterns
Design PatternsDesign Patterns
Design Patternssoms_1
 
Refactoring - An Introduction
Refactoring - An IntroductionRefactoring - An Introduction
Refactoring - An IntroductionGiorgio Vespucci
 
The Decorator Pattern
The Decorator PatternThe Decorator Pattern
The Decorator PatternAkshat Vig
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101Adam Culp
 
Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材teddysoft
 
Design Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator PatternDesign Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator Patterneprafulla
 

Viewers also liked (12)

Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
saleh nazzal
saleh nazzalsaleh nazzal
saleh nazzal
 
عربي
عربيعربي
عربي
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Refactoring - An Introduction
Refactoring - An IntroductionRefactoring - An Introduction
Refactoring - An Introduction
 
The Decorator Pattern
The Decorator PatternThe Decorator Pattern
The Decorator Pattern
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101
 
Refactoring
RefactoringRefactoring
Refactoring
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材
 
Design Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator PatternDesign Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator Pattern
 
SlideShare 101
SlideShare 101SlideShare 101
SlideShare 101
 

Similar to Design Patterns Illustrated

Designpatterns illustrated
Designpatterns illustratedDesignpatterns illustrated
Designpatterns illustratedNhat Vo Van
 
Design patterns illustrated-2015-03
Design patterns illustrated-2015-03Design patterns illustrated-2015-03
Design patterns illustrated-2015-03Herman Peeren
 
I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?sbjug
 
I didn't know you could do that with groovy
I didn't know you could do that with groovyI didn't know you could do that with groovy
I didn't know you could do that with groovySteven Hicks
 
Design Patterns Part1
Design Patterns  Part1Design Patterns  Part1
Design Patterns Part1Tom Chen
 
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....AboutYouGmbH
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascriptAyush Sharma
 
Design patterns illustrated 010PHP
Design patterns illustrated 010PHPDesign patterns illustrated 010PHP
Design patterns illustrated 010PHPHerman Peeren
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_ivNico Ludwig
 
(4) c sharp introduction_object_orientation_part_i
(4) c sharp introduction_object_orientation_part_i(4) c sharp introduction_object_orientation_part_i
(4) c sharp introduction_object_orientation_part_iNico Ludwig
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to ClojureRenzo Borgatti
 
Mixing Diagram, Tree, Text, Table and Form editors to build a kick-ass modeli...
Mixing Diagram, Tree, Text, Table and Form editors to build a kick-ass modeli...Mixing Diagram, Tree, Text, Table and Form editors to build a kick-ass modeli...
Mixing Diagram, Tree, Text, Table and Form editors to build a kick-ass modeli...Chauvin Mariot
 
Smalltalk, the dynamic language
Smalltalk, the dynamic languageSmalltalk, the dynamic language
Smalltalk, the dynamic languagemohamedsamyali
 
Post-graduate course: Object technology: Implementation of object-oriented pr...
Post-graduate course: Object technology: Implementation of object-oriented pr...Post-graduate course: Object technology: Implementation of object-oriented pr...
Post-graduate course: Object technology: Implementation of object-oriented pr...Baltasar García Perez-Schofield
 
Deep Dive into Monads and Cats Lib
Deep Dive into Monads and Cats LibDeep Dive into Monads and Cats Lib
Deep Dive into Monads and Cats LibKnoldus Inc.
 
Effects, coeffects & subscriptions: a pit of success for SPAs Socracan18
Effects, coeffects & subscriptions: a pit of success for SPAs Socracan18Effects, coeffects & subscriptions: a pit of success for SPAs Socracan18
Effects, coeffects & subscriptions: a pit of success for SPAs Socracan18Manuel Rivero
 
Concurrency - Why it's hard ?
Concurrency - Why it's hard ?Concurrency - Why it's hard ?
Concurrency - Why it's hard ?Ramith Jayasinghe
 
Design Pattern lecture 2
Design Pattern lecture 2Design Pattern lecture 2
Design Pattern lecture 2Julie Iskander
 

Similar to Design Patterns Illustrated (20)

Designpatterns illustrated
Designpatterns illustratedDesignpatterns illustrated
Designpatterns illustrated
 
Design patterns illustrated-2015-03
Design patterns illustrated-2015-03Design patterns illustrated-2015-03
Design patterns illustrated-2015-03
 
I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?
 
I didn't know you could do that with groovy
I didn't know you could do that with groovyI didn't know you could do that with groovy
I didn't know you could do that with groovy
 
Design Patterns Part1
Design Patterns  Part1Design Patterns  Part1
Design Patterns Part1
 
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascript
 
Design patterns illustrated 010PHP
Design patterns illustrated 010PHPDesign patterns illustrated 010PHP
Design patterns illustrated 010PHP
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
 
(4) c sharp introduction_object_orientation_part_i
(4) c sharp introduction_object_orientation_part_i(4) c sharp introduction_object_orientation_part_i
(4) c sharp introduction_object_orientation_part_i
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to Clojure
 
Mixing Diagram, Tree, Text, Table and Form editors to build a kick-ass modeli...
Mixing Diagram, Tree, Text, Table and Form editors to build a kick-ass modeli...Mixing Diagram, Tree, Text, Table and Form editors to build a kick-ass modeli...
Mixing Diagram, Tree, Text, Table and Form editors to build a kick-ass modeli...
 
Smalltalk, the dynamic language
Smalltalk, the dynamic languageSmalltalk, the dynamic language
Smalltalk, the dynamic language
 
Post-graduate course: Object technology: Implementation of object-oriented pr...
Post-graduate course: Object technology: Implementation of object-oriented pr...Post-graduate course: Object technology: Implementation of object-oriented pr...
Post-graduate course: Object technology: Implementation of object-oriented pr...
 
Deep Dive into Monads and Cats Lib
Deep Dive into Monads and Cats LibDeep Dive into Monads and Cats Lib
Deep Dive into Monads and Cats Lib
 
Multi screenlab
Multi screenlabMulti screenlab
Multi screenlab
 
Effects, coeffects & subscriptions: a pit of success for SPAs Socracan18
Effects, coeffects & subscriptions: a pit of success for SPAs Socracan18Effects, coeffects & subscriptions: a pit of success for SPAs Socracan18
Effects, coeffects & subscriptions: a pit of success for SPAs Socracan18
 
Concurrency - Why it's hard ?
Concurrency - Why it's hard ?Concurrency - Why it's hard ?
Concurrency - Why it's hard ?
 
Design Pattern lecture 2
Design Pattern lecture 2Design Pattern lecture 2
Design Pattern lecture 2
 
Hibernate 1x2
Hibernate 1x2Hibernate 1x2
Hibernate 1x2
 

More from Herman Peeren

ProjectionalForms-2023-11-14.pdf
ProjectionalForms-2023-11-14.pdfProjectionalForms-2023-11-14.pdf
ProjectionalForms-2023-11-14.pdfHerman Peeren
 
ExtensionGenerator-JoomlaDagen2023-slides.pdf
ExtensionGenerator-JoomlaDagen2023-slides.pdfExtensionGenerator-JoomlaDagen2023-slides.pdf
ExtensionGenerator-JoomlaDagen2023-slides.pdfHerman Peeren
 
Programmeren, talen en het begrijpen van de wereld
Programmeren, talen en het begrijpen van de wereldProgrammeren, talen en het begrijpen van de wereld
Programmeren, talen en het begrijpen van de wereldHerman Peeren
 
Improve our PHP code with ideas from Functional Programming
Improve our PHP code with ideas from Functional ProgrammingImprove our PHP code with ideas from Functional Programming
Improve our PHP code with ideas from Functional ProgrammingHerman Peeren
 
DCI DDD-BE April 2015
DCI DDD-BE April 2015DCI DDD-BE April 2015
DCI DDD-BE April 2015Herman Peeren
 
Next Generation Joomla!
Next Generation Joomla!Next Generation Joomla!
Next Generation Joomla!Herman Peeren
 
Behat, Behavioral Driven Development (BDD) in PHP
Behat, Behavioral Driven Development (BDD) in PHPBehat, Behavioral Driven Development (BDD) in PHP
Behat, Behavioral Driven Development (BDD) in PHPHerman Peeren
 
Print, geen kunst aan
Print, geen kunst aanPrint, geen kunst aan
Print, geen kunst aanHerman Peeren
 
Jooctrine - Doctrine ORM in Joomla!
Jooctrine - Doctrine ORM in Joomla!Jooctrine - Doctrine ORM in Joomla!
Jooctrine - Doctrine ORM in Joomla!Herman Peeren
 
#jd12nl Joomla 2.5 extensies
#jd12nl Joomla 2.5 extensies#jd12nl Joomla 2.5 extensies
#jd12nl Joomla 2.5 extensiesHerman Peeren
 
Jug010 120320-templates
Jug010 120320-templatesJug010 120320-templates
Jug010 120320-templatesHerman Peeren
 
Joomla2.0 architecture
Joomla2.0 architectureJoomla2.0 architecture
Joomla2.0 architectureHerman Peeren
 
Webservices: connecting Joomla! with other programs.
Webservices: connecting Joomla! with other programs.Webservices: connecting Joomla! with other programs.
Webservices: connecting Joomla! with other programs.Herman Peeren
 
Commercial gpljoomla
Commercial gpljoomlaCommercial gpljoomla
Commercial gpljoomlaHerman Peeren
 
Flash templates for Joomla!
Flash templates for Joomla!Flash templates for Joomla!
Flash templates for Joomla!Herman Peeren
 

More from Herman Peeren (19)

ProjectionalForms-2023-11-14.pdf
ProjectionalForms-2023-11-14.pdfProjectionalForms-2023-11-14.pdf
ProjectionalForms-2023-11-14.pdf
 
ExtensionGenerator-JoomlaDagen2023-slides.pdf
ExtensionGenerator-JoomlaDagen2023-slides.pdfExtensionGenerator-JoomlaDagen2023-slides.pdf
ExtensionGenerator-JoomlaDagen2023-slides.pdf
 
Cut & Shave
Cut & ShaveCut & Shave
Cut & Shave
 
Programmeren, talen en het begrijpen van de wereld
Programmeren, talen en het begrijpen van de wereldProgrammeren, talen en het begrijpen van de wereld
Programmeren, talen en het begrijpen van de wereld
 
Dci in PHP
Dci in PHPDci in PHP
Dci in PHP
 
Improve our PHP code with ideas from Functional Programming
Improve our PHP code with ideas from Functional ProgrammingImprove our PHP code with ideas from Functional Programming
Improve our PHP code with ideas from Functional Programming
 
DCI DDD-BE April 2015
DCI DDD-BE April 2015DCI DDD-BE April 2015
DCI DDD-BE April 2015
 
Event Sourcing
Event SourcingEvent Sourcing
Event Sourcing
 
Next Generation Joomla!
Next Generation Joomla!Next Generation Joomla!
Next Generation Joomla!
 
Behat, Behavioral Driven Development (BDD) in PHP
Behat, Behavioral Driven Development (BDD) in PHPBehat, Behavioral Driven Development (BDD) in PHP
Behat, Behavioral Driven Development (BDD) in PHP
 
Print, geen kunst aan
Print, geen kunst aanPrint, geen kunst aan
Print, geen kunst aan
 
Jooctrine - Doctrine ORM in Joomla!
Jooctrine - Doctrine ORM in Joomla!Jooctrine - Doctrine ORM in Joomla!
Jooctrine - Doctrine ORM in Joomla!
 
#jd12nl Joomla 2.5 extensies
#jd12nl Joomla 2.5 extensies#jd12nl Joomla 2.5 extensies
#jd12nl Joomla 2.5 extensies
 
#jd12nl Seblod 2
#jd12nl  Seblod 2#jd12nl  Seblod 2
#jd12nl Seblod 2
 
Jug010 120320-templates
Jug010 120320-templatesJug010 120320-templates
Jug010 120320-templates
 
Joomla2.0 architecture
Joomla2.0 architectureJoomla2.0 architecture
Joomla2.0 architecture
 
Webservices: connecting Joomla! with other programs.
Webservices: connecting Joomla! with other programs.Webservices: connecting Joomla! with other programs.
Webservices: connecting Joomla! with other programs.
 
Commercial gpljoomla
Commercial gpljoomlaCommercial gpljoomla
Commercial gpljoomla
 
Flash templates for Joomla!
Flash templates for Joomla!Flash templates for Joomla!
Flash templates for Joomla!
 

Recently uploaded

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 

Recently uploaded (20)

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 

Design Patterns Illustrated

  • 1. Design Patterns illustrated Herman Peeren May 31st 2010 (DP-illustrations: Nelleke Verhoeff)
  • 2. Design Patterns ●● recipes against common (OO-) programming problems ●● code reuse: no need to reinvent the wheel ●● common language ●● GOF: 23 “classical” patterns classic, The Book very nice!
  • 3. The one constant in software development:
  • 4. The one constant in software development: CHANGE!
  • 5. The one constant in software development: CHANGE! I knew it ...
  • 6. Ideal: code as modular black boxes
  • 7. Wish list and OOP-principles ●● loose coupling: 1 change = ceteris paribus ●● code reuse (is not the same as copy/paste) ●● open for extension, closed for modification ●● encapsulate what varies ●● single responsibility principle ●● program against an interface not against an imple- mentation. Dependency injection ●● prefer composition over inheritance (in fact this is all the same with different words)
  • 9. It might get you into trouble...
  • 11. some code smells: 1.● duplicate code: DRY 2.● long method, huge class: SRP 3.● combinatorial explosion (similar classes) 4.● conditional complexity, switch statements 5.● “exhibitionistic” classes
  • 12. some code smells: 1.● duplicate code: DRY 2.● long method, huge class: SRP 3.● combinatorial explosion (similar classes) 4.● conditional complexity, switch statements 5.● “exhibitionistic” classes
  • 13. Classic pattern categories creational, structural and behavioral patterns: ●● creational: object instantiation ●● structural: larger structures of classes or objects ●● behavioral: interaction and distribution of responsibility
  • 14. Creational design patterns ●● Factory Method: Allow subclasses to “decide” which class to instantiate. ●● Abstract Factory: Encapsulate a set of analo- gous factories that produce families of objects. ●● Builder: Encapsulate the construction of com- plex objects from their representation; so, the same building process can create various repre- sentations by specifying only type and content. ●● Singleton: Ensure that only a single instance of a class exists and provide a single method for gaining access to it. ●● Prototype: Create an initialized instance for cloning or copying.
  • 15. Factory Method Provide an interface for the creation of objects. Allow subclasses to “decide” which class to instantiate. c
  • 16. Abstract Factory Povide an interface for creating families of related or dependent objects. A factory for factories. c
  • 17. Builder Seperate the construction process (how) of a complex object from the concrete representations (what). c
  • 18. Singleton Ensure a class only has one instance, and provide a global point of access to it. Oh, I’m so loooooooonly c
  • 19. Joomla! ●● JFactory: a class with static methods to instantiate objects like JDatabase, JUser, JDocument, JTemplate, etc. ●● most of those methods are singletons Nooku ●● KFactory: any class can be instantiated ●● get() = singleton, tmp() = any instantiation
  • 20. “Every advantage has its disadvantages” (free to Johan Cruyff, Dutch Football Pattern Designer and Ajax-fan...)
  • 21. Prototype Make variations on copies of a basic-object. COPY-SERVICE c
  • 22. Structural design patterns ●● Adapter: Adapt an interface to an expected interface. ●● Bridge: Decouple an interface from its implementation. ●● Composite: Create a tree structure for part-whole hierarchies. ●● Decorator: Extend functionality dynamically. ●● Facade: Simplify usage by defining a high-level interface. ●● Flyweight: Support fine-grained objects efficiently by sharing. ●● Proxy: Represent an object with another object for access control.
  • 23. Adapter (= Wrapper) c Adapt an interface to an expected interface.
  • 24. Joomla! ●● new in 1.6: JAdapter and JAdapterInstance ●● JUpdateAdapter extends JAdapterInstance JUpdaterExtension & JUpdaterExtension extend JUpdateAdapter wanted: documentation and examples! what does it adapt?
  • 25. Bridge Decouple an abstraction from its implementation. COLA 1 LITER 1 LITER COLA 1 LITER 1 LITER COLA MILK COLA MILK COLA MILK c
  • 26. Composite Create a tree structure for part-whole hierarchies. A node is also a (part of a) tree. Recursive: c
  • 27. Decorator Add extra functionallity (at runtime), while keeping the interface the same. Matroushka’s... c
  • 28. Decorator Nooku ●● KPatternDecorator: a general decorator ●● e.g. extended by KDecoratorJoomlaApplication
  • 29. Facade Provide a general (simpler) interface for a set of interfaces. looks simple c
  • 30. Flyweight Use one instance of a class to provide many “virtual” instances. c
  • 31. Proxy Provide a surrogate or placeholder for another object to control access to it. c
  • 32. Behavioral design patterns ●● Chain of Responsibility: Define a method of passing a request among a chain of objects. ●● Command: Encapsulate a command request in an object. ●● Interpreter: Allow inclusion of language elements in an appli- cation. ●● Iterator: Enable sequential access to collection elements. ●● Mediator: Define simplified communication between classes. ●● Memento: Save and restore the internal state of an object. ●● Observer: Define a scheme for notifying objects of changes to another object. ●● State: Alter the behavior of an object when its state changes. ●● Strategy: Encapsulate an algorithm inside a class. ●● Template Method: Allow subclasses to redefine the steps of an algorithm. ●● Visitor: Define a new operation on a class without changing it.
  • 33. Command Encapsulate a command request in an object. YOU,DO YOUR TASK! TASK TASK LIGHT LIGHT ON OFF c
  • 34. Chain of Responsibility c Define a method of passing a request among a chain of objects.
  • 35. Nooku ●● KCommandChain + KCommandContext, KCommandEvent, KCommandHandler and KCommandInterface ●● N.B.: executes a series of commands instead of passing a command to a series of handlers (like in Tapestry e.g.) ...correct me if I’m wrong....
  • 36. Interpreter Domain -> (little) language -> grammar -> objects (DSL) HÉ! he means: do this, do that, and after finishing it, go there! c
  • 37. Iterator Enable sequential access to collection elements, without showing the underlying data-structures (array, list, records, etc) next next c
  • 38. Mediator c Layer in between: communication via one object.
  • 39. Memento Save and restore the internal state of an object. ME c
  • 40. Observer Notify “subscribers” of changes. ME NO ME ME WHO? c
  • 41. Joomla! ●● JObserver and JObservable ●● JObserver extended by JEvent and that by JPlugin Nooku ●● KPatternObserver and KPatternObservable
  • 42. State Let an object show other methods after a change of internal state (as if it changes it’s class). in a.....hick......different state, ....hick....I behave differently....hick..... c
  • 43. Strategy When something can be done in several ways, make those ways interchangeable. POSSI- BILITIES c
  • 44.
  • 45. Template Method The skeleton of an algorithm is fixed, but parts can be filled in differently. c
  • 46. Visitor Make a kind of plugin-possibility for methods: in that way me- thods can be added in runtime. printservice! c
  • 47. extra: Mixin ●● Used in Nooku (and a.o. in Ruby and Python) ●● a kind of abstract class that is mixed into another object ●● all methods of the mixin are now part of the object ●● handle with care: beware of tight coupling....
  • 48. Golden OO-principles ●● encapsulate what varies, OCP ●● 1class, 1 responsibility, SRP ●● program against an interface, not against an imple- mentation, DIP ●● prefer composition over inheritance ●● loose coupling, modular black boxes
  • 49. Some books GOF: 23 “classical” patterns: very nice! classic, The Book handy examples
  • 50. good start Fowler: extended e.g. with patterns for web Fowler: also known from refactoring combi: re- factoring & patterns
  • 51. Resign Patterns: Ailments of Unsuitable Project-Disoriented Software
  • 52. Joomla! Could be improved by studying design patterns and applying them. Loose coupling...
  • 53. Questions? Contact info: Herman Peeren herman@yepr.nl © Yepr The artwork in this presentation is provided under the Creative Commons Public License for noncommercial use. http://creativecommons.org/licenses/by-nc/3.0/legalcode