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

Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patternsAmit Kabra
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in JavaIonut Bilica
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns pptAman Jain
 
Dependency injection presentation
Dependency injection presentationDependency injection presentation
Dependency injection presentationAhasanul Kalam Akib
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaEdureka!
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternMudasir Qazi
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK ExamplesEnder Aydin Orak
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Hitesh-Java
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design PatternJaswant Singh
 
Clean code: SOLID (iOS)
Clean code: SOLID (iOS)Clean code: SOLID (iOS)
Clean code: SOLID (iOS)Maksym Husar
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 

What's hot (20)

Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
Design patterns tutorials
Design patterns tutorialsDesign patterns tutorials
Design patterns tutorials
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
Dependency injection presentation
Dependency injection presentationDependency injection presentation
Dependency injection presentation
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | Edureka
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK Examples
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Clean code: SOLID (iOS)
Clean code: SOLID (iOS)Clean code: SOLID (iOS)
Clean code: SOLID (iOS)
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Design patterns
Design patternsDesign patterns
Design patterns
 

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 (11)

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這樣學就會了:入門班 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

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
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
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Recently uploaded (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
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.
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
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
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

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