SlideShare a Scribd company logo
AMIR BARYLKO
                  ADVANCED
               DESIGN PATTERNS


Amir Barylko               Advanced Design Patterns
WHO AM I?

  • Software     quality expert

  • Architect

  • Developer

  • Mentor

  • Great      cook

  • The    one who’s entertaining you for the next hour!
Amir Barylko                                          Advanced Desing Patterns
RESOURCES

  • Email: amir@barylko.com

  • Twitter: @abarylko

  • Blog: http://www.orthocoders.com

  • Materials: http://www.orthocoders.com/presentations




Amir Barylko                                      Advanced Desing Patterns
PATTERNS
                    What are they?
                What are anti-patterns?
               Which patterns do you use?




Amir Barylko                                Advanced Design Patterns
WHAT ARE PATTERNS?

  •Software         design Recipe
  •or     Solution
  •Should         be reusable
  •Should         be general
  •No          particular language
Amir Barylko                         Advanced Design Patterns
ANTI-PATTERNS
  •   More patterns != better design

  •   No cookie cutter

  •   Anti Patterns : Patterns to identify failure

      •   God Classes

      •   High Coupling

      •   Breaking SOLID principles....

      •   (name some)
Amir Barylko                                         Advanced Design Patterns
WHICH PATTERNS
                   DO YOU USE?
  • Fill   here with your patterns:




Amir Barylko                          Advanced Design Patterns
ADVANCED PATTERNS
                     Let’s vote!




Amir Barylko                       Advanced Design Patterns
SOME PATTERNS...

  •   Chain of resp.     •   List            •   Composite
                             Comprehension
  •   Proxy                                  •   State
                         •   Object Mother
  •   ActiveRecord                           •   Strategy
                         •   Visitor
  •   Repository                             •   Iterator
                         •   Null Object
  •   Event Aggregator                       •   DTO
                         •   Factory
  •   Event Sourcing                         •   Page Object
                         •   Command
Amir Barylko                                         Advanced Desing Patterns
CHAIN OF RESPONSIBILITY

  • More   than one object may handle a request, and the handler
    isn't known a priori.

  • The    handler should be ascertained automatically.

  • You want to issue request to one of several objects without
    specifying The receiver explicitly.

  • The set of objects that can handle a request should be
    specified dynamically

Amir Barylko                                          Advanced Design Patterns
Amir Barylko   Advanced Design Patterns
PROXY

  • Avoid       creating the object until needed

  • Provides      a placeholder for additional functionality

  • Very       useful for mocking

  • Many       implementations exist (IoC, Dynamic proxies, etc)




Amir Barylko                                               Advanced Design Patterns
GOF
ACTIVERECORD

  • Isa Domain Model where classes match very closely the
    database structure

  • Each table is mapped to class with methods for finding,
    update, delete, etc.

  • Each       attribute is mapped to a column

  • Associations      are deduced from the classes


Amir Barylko                                         Advanced Design Patterns
create_table   "movies", :force => true do |t|
    t.string     "title"
    t.string     "description"
    t.datetime   "created_at"
    t.datetime   "updated_at"
  end

  create_table   "reviews", :force => true do |t|
    t.string     "name"
    t.integer    "stars"
    t.text       "comment"
    t.integer    "movie_id"
    t.datetime   "created_at"
    t.datetime   "updated_at"
  end

   class Movie < ActiveRecord::Base
     validates_presence_of :title, :description
     has_many :reviews
   end
   class Review < ActiveRecord::Base
     belongs_to :movie
   end


Amir Barylko                                        Advanced Design Patterns
REPOSITORY

  • Mediator        between domain and storage

  • Acts       like a collection of items

  • Supports        queries

  • Abstraction       of the storage




Amir Barylko                                     Advanced Design Patterns
http://martinfowler.com/eaaCatalog/repository.html
Amir Barylko                                     Advanced Design Patterns
EVENT AGGREGATOR

  • Manage      events using a subscribe / publish mechanism

  • Isolates   subscribers from publishers

  • Decouple      events from actual models

  • Events     can be distributed

  • Centralize    event registration logic

  • No    need to track multiple objects
Amir Barylko                                           Advanced Design Patterns
Channel events
  from multiple
  objects into a
  single object to
  s i m p l i f y
  registration for
  clients



Amir Barylko         Advanced Design Patterns
MT COMMONS




Amir Barylko                Advanced Design Patterns
EVENT SOURCING

  • Register     all changes in the application using events

  • Event      should be persisted

  • Complete       Rebuild

  • Temporal      Query

  • Event      Replay


Amir Barylko                                              Advanced Design Patterns
http://martinfowler.com/eaaDev/EventSourcing.html
Amir Barylko                                    Advanced Design Patterns
Amir Barylko   Advanced Design Patterns
LIST COMPREHENSION

  • Syntax      Construct in languages

  • Describe      properties for the list (sequence)

  • Filter

  • Mapping

  • Same       idea for Set or Dictionary comprehension


Amir Barylko                                              Advanced Design Patterns
LANGUAGE COMPARISON
  • Scala
   for (x <- Stream.from(0); if x*x > 3) yield 2*x

  • LINQ
   var range = Enumerable.Range(0..20);
   from num in range where num * num > 3 select num * 2;

  • Clojure
   (take 20 (for [x (iterate inc 0) :when (> (* x x) 3)] (* 2 x)))


  • Ruby
   (1..20).select { |x| x * x > 3 }.map { |x| x * 2 }


Amir Barylko                                          Advanced Design Patterns
OBJECT MOTHER / BUILDER

  • Creates       an object for testing (or other) purposes

  • Assumes        defaults

  • Easy    to configure

  • Fluid      interface

  • Usually      has methods to to easily manipulate the domain


Amir Barylko                                              Advanced Design Patterns
public class When_adding_a_an_invalid_extra_frame
   {
       [Test]
       public void Should_throw_an_exception()
       {
           // arrange
           10.Times(() => this.GameBuilder.AddFrame(5, 4));

               var game = this.GameBuilder.Build();

               // act & assert
               new Action(() => game.Roll(8)).Should().Throw();
         }
   }




               http://orthocoders.com/2011/09/05/the-bowling-game-kata-first-attempt/


Amir Barylko                                                                Advanced Design Patterns
Amir Barylko   Advanced Design Patterns
VISITOR

  • Ability    to traverse (visit) a object structure

  • Different     visitors may produce different results

  • Avoid      littering the classes with particular operations




Amir Barylko                                               Advanced Design Patterns
http://en.wikipedia.org/wiki/Visitor_pattern#Diagram
Amir Barylko                                     Advanced Design Patterns
NULL OBJECT

  • Represent “null” with      an actual instance

  • Provides      default functionality

  • Clear      semantics of “null” for that domain




Amir Barylko                                         Advanced Design Patterns
class animal {
    public:
       virtual void make_sound() = 0;
    };

    class dog : public animal {
       void make_sound() { cout << "woof!" << endl; }
    };

    class null_animal : public animal {
       void make_sound() { }
    };




           http://en.wikipedia.org/wiki/Null_Object_pattern


Amir Barylko                                      Advanced Design Patterns
FACTORY

  • Creates      instances by request

  • More       flexible than Singleton

  • Can    be configured to create different families of objects

  • IoC    containers are closely related

  • Can    be implemented dynamic based on interfaces

  • Can    be used also to release “resource” when not needed
Amir Barylko                                           Advanced Design Patterns
interface GUIFactory {
       public Button createButton();
   }

   class WinFactory implements GUIFactory {
       public Button createButton() {
           return new WinButton();
       }
   }
   class OSXFactory implements GUIFactory {
       public Button createButton() {
           return new OSXButton();
       }
   }

   interface Button {
       public void paint();
   }


      http://en.wikipedia.org/wiki/Abstract_factory_pattern
Amir Barylko                                    Advanced Design Patterns
STRATEGY

  • Abstracts   the algorithm to solve a particular problem

  • Can    be configured dynamically

  • Are    interchangeable




Amir Barylko                                          Advanced Design Patterns
http://orthocoders.com/2010/04/
Amir Barylko                                     Advanced Design Patterns
DATA TRANSFER OBJECT

  • Simplifies   information transfer across services

  • Can    be optimized

  • Easy   to understand




Amir Barylko                                           Advanced Design Patterns
http://martinfowler.com/eaaCatalog/dataTransferObject.html
Amir Barylko                                 Advanced Design Patterns
PAGE OBJECT

  • Abstract      web pages functionality to be used usually in testing

  • Each       page can be reused

  • Changes       in the page impact only the implementation, not the
    clients




Amir Barylko                                              Advanced Design Patterns
public class LoginPage {
     public HomePage loginAs(String username, String password) {
         // ... clever magic happens here
     }
    
     public LoginPage loginWithError(String username, String
 password) {
         //  ... failed login here, maybe because
         // one or both of the username and password are wrong
     }
    
     public String getErrorMessage() {
         // So we can verify that the correct error is shown
     }
 }




       http://code.google.com/p/selenium/wiki/PageObjects
Amir Barylko                                         Advanced Design Patterns
QUESTIONS?




Amir Barylko                Advanced Design Patterns
RESOURCES

  • Email: amir@barylko.com, @abarylko

  • Slides: http://www.orthocoders.com/presentations

  • Patterns: Each   pattern example has a link




Amir Barylko                                      Advanced Design Patterns
RESOURCES II




Amir Barylko                  Advanced Desing Patterns
RESOURCES III




Amir Barylko                   Advanced Desing Patterns
CLOJURE TRAINING

  • When: Nov       6, 7 & 8

  • More       info: http://www.maventhought.com

  • Goal: LearnClojure and functional programming with real
    hands on examples




Amir Barylko                                      Advanced Desing Patterns

More Related Content

PDF
PRDCW-advanced-design-patterns
PDF
Agile requirements
PDF
Agile planning
PDF
YEG-Agile-planning
PDF
agile-planning
PDF
CPL12-Agile-planning
PDF
PRDC12 advanced design patterns
PDF
Agile requirements
PRDCW-advanced-design-patterns
Agile requirements
Agile planning
YEG-Agile-planning
agile-planning
CPL12-Agile-planning
PRDC12 advanced design patterns
Agile requirements

What's hot (8)

KEY
Android java fx-jme@jug-lugano
PPTX
iCharge & iStand
KEY
Writing Storyboards
PDF
Sdec11 when user stories are not enough
KEY
Deep Dive into Flex Mobile Item Renderers
PDF
Aft 157 design process project -ii
PDF
AspireLabs! Startup Summer
PDF
Arbyte - A modular, flexible, scalable job queing and execution system
Android java fx-jme@jug-lugano
iCharge & iStand
Writing Storyboards
Sdec11 when user stories are not enough
Deep Dive into Flex Mobile Item Renderers
Aft 157 design process project -ii
AspireLabs! Startup Summer
Arbyte - A modular, flexible, scalable job queing and execution system
Ad

Similar to sdec11-Advanced-design-patterns (20)

PDF
Code camp 2012-advanced-design-patterns
PPTX
Gof design patterns
PDF
Design patterns for fun & profit - CoderCruise 2018
PPTX
Design Pattern - Introduction
PPTX
Sofwear deasign and need of design pattern
PDF
software engineering Design Patterns.pdf
PPT
Design pattern
PPT
Design Patterns
PDF
Cse 6007 fall2012
PDF
Design patterns through java
PPTX
Design patterns
PDF
Design Patterns Java programming language.pdf
DOCX
Java Design Pattern Interview Questions
PDF
Style & Design Principles 02 - Design Patterns
PPTX
PPS
Design Patterns For 70% Of Programmers In The World
PPT
Introduction to design patterns
PDF
Design Patterns Summer Course 2009-2010 - Session#1
PPT
5 Design Patterns Explained
PPT
Design pattern & categories
Code camp 2012-advanced-design-patterns
Gof design patterns
Design patterns for fun & profit - CoderCruise 2018
Design Pattern - Introduction
Sofwear deasign and need of design pattern
software engineering Design Patterns.pdf
Design pattern
Design Patterns
Cse 6007 fall2012
Design patterns through java
Design patterns
Design Patterns Java programming language.pdf
Java Design Pattern Interview Questions
Style & Design Principles 02 - Design Patterns
Design Patterns For 70% Of Programmers In The World
Introduction to design patterns
Design Patterns Summer Course 2009-2010 - Session#1
5 Design Patterns Explained
Design pattern & categories
Ad

More from Amir Barylko (20)

PDF
Functional converter project
PDF
Elm: delightful web development
PDF
Dot Net Core
PDF
No estimates
PDF
User stories deep dive
PDF
Coderetreat hosting training
PDF
There's no charge for (functional) awesomeness
PDF
What's new in c# 6
PDF
Productive teams
PDF
Who killed object oriented design?
PDF
From coach to owner - What I learned from the other side
PDF
Communication is the Key to Teamwork and productivity
PDF
Acceptance Test Driven Development
PDF
Refactoring
PDF
Agile teams and responsibilities
PDF
Refactoring
PDF
Beutiful javascript with coffeescript
PDF
Sass & bootstrap
PDF
Rich UI with Knockout.js &amp; Coffeescript
PDF
SDEC12 Beautiful javascript with coffeescript
Functional converter project
Elm: delightful web development
Dot Net Core
No estimates
User stories deep dive
Coderetreat hosting training
There's no charge for (functional) awesomeness
What's new in c# 6
Productive teams
Who killed object oriented design?
From coach to owner - What I learned from the other side
Communication is the Key to Teamwork and productivity
Acceptance Test Driven Development
Refactoring
Agile teams and responsibilities
Refactoring
Beutiful javascript with coffeescript
Sass & bootstrap
Rich UI with Knockout.js &amp; Coffeescript
SDEC12 Beautiful javascript with coffeescript

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
KodekX | Application Modernization Development
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
Teaching material agriculture food technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Electronic commerce courselecture one. Pdf
MIND Revenue Release Quarter 2 2025 Press Release
Mobile App Security Testing_ A Comprehensive Guide.pdf
Network Security Unit 5.pdf for BCA BBA.
Chapter 3 Spatial Domain Image Processing.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KodekX | Application Modernization Development
Reach Out and Touch Someone: Haptics and Empathic Computing
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Unlocking AI with Model Context Protocol (MCP)
Understanding_Digital_Forensics_Presentation.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Spectral efficient network and resource selection model in 5G networks
Teaching material agriculture food technology

sdec11-Advanced-design-patterns

  • 1. AMIR BARYLKO ADVANCED DESIGN PATTERNS Amir Barylko Advanced Design Patterns
  • 2. WHO AM I? • Software quality expert • Architect • Developer • Mentor • Great cook • The one who’s entertaining you for the next hour! Amir Barylko Advanced Desing Patterns
  • 3. RESOURCES • Email: amir@barylko.com • Twitter: @abarylko • Blog: http://www.orthocoders.com • Materials: http://www.orthocoders.com/presentations Amir Barylko Advanced Desing Patterns
  • 4. PATTERNS What are they? What are anti-patterns? Which patterns do you use? Amir Barylko Advanced Design Patterns
  • 5. WHAT ARE PATTERNS? •Software design Recipe •or Solution •Should be reusable •Should be general •No particular language Amir Barylko Advanced Design Patterns
  • 6. ANTI-PATTERNS • More patterns != better design • No cookie cutter • Anti Patterns : Patterns to identify failure • God Classes • High Coupling • Breaking SOLID principles.... • (name some) Amir Barylko Advanced Design Patterns
  • 7. WHICH PATTERNS DO YOU USE? • Fill here with your patterns: Amir Barylko Advanced Design Patterns
  • 8. ADVANCED PATTERNS Let’s vote! Amir Barylko Advanced Design Patterns
  • 9. SOME PATTERNS... • Chain of resp. • List • Composite Comprehension • Proxy • State • Object Mother • ActiveRecord • Strategy • Visitor • Repository • Iterator • Null Object • Event Aggregator • DTO • Factory • Event Sourcing • Page Object • Command Amir Barylko Advanced Desing Patterns
  • 10. CHAIN OF RESPONSIBILITY • More than one object may handle a request, and the handler isn't known a priori. • The handler should be ascertained automatically. • You want to issue request to one of several objects without specifying The receiver explicitly. • The set of objects that can handle a request should be specified dynamically Amir Barylko Advanced Design Patterns
  • 11. Amir Barylko Advanced Design Patterns
  • 12. PROXY • Avoid creating the object until needed • Provides a placeholder for additional functionality • Very useful for mocking • Many implementations exist (IoC, Dynamic proxies, etc) Amir Barylko Advanced Design Patterns
  • 13. GOF
  • 14. ACTIVERECORD • Isa Domain Model where classes match very closely the database structure • Each table is mapped to class with methods for finding, update, delete, etc. • Each attribute is mapped to a column • Associations are deduced from the classes Amir Barylko Advanced Design Patterns
  • 15. create_table "movies", :force => true do |t| t.string "title" t.string "description" t.datetime "created_at" t.datetime "updated_at" end create_table "reviews", :force => true do |t| t.string "name" t.integer "stars" t.text "comment" t.integer "movie_id" t.datetime "created_at" t.datetime "updated_at" end class Movie < ActiveRecord::Base validates_presence_of :title, :description has_many :reviews end class Review < ActiveRecord::Base belongs_to :movie end Amir Barylko Advanced Design Patterns
  • 16. REPOSITORY • Mediator between domain and storage • Acts like a collection of items • Supports queries • Abstraction of the storage Amir Barylko Advanced Design Patterns
  • 18. EVENT AGGREGATOR • Manage events using a subscribe / publish mechanism • Isolates subscribers from publishers • Decouple events from actual models • Events can be distributed • Centralize event registration logic • No need to track multiple objects Amir Barylko Advanced Design Patterns
  • 19. Channel events from multiple objects into a single object to s i m p l i f y registration for clients Amir Barylko Advanced Design Patterns
  • 20. MT COMMONS Amir Barylko Advanced Design Patterns
  • 21. EVENT SOURCING • Register all changes in the application using events • Event should be persisted • Complete Rebuild • Temporal Query • Event Replay Amir Barylko Advanced Design Patterns
  • 23. Amir Barylko Advanced Design Patterns
  • 24. LIST COMPREHENSION • Syntax Construct in languages • Describe properties for the list (sequence) • Filter • Mapping • Same idea for Set or Dictionary comprehension Amir Barylko Advanced Design Patterns
  • 25. LANGUAGE COMPARISON • Scala for (x <- Stream.from(0); if x*x > 3) yield 2*x • LINQ var range = Enumerable.Range(0..20); from num in range where num * num > 3 select num * 2; • Clojure (take 20 (for [x (iterate inc 0) :when (> (* x x) 3)] (* 2 x))) • Ruby (1..20).select { |x| x * x > 3 }.map { |x| x * 2 } Amir Barylko Advanced Design Patterns
  • 26. OBJECT MOTHER / BUILDER • Creates an object for testing (or other) purposes • Assumes defaults • Easy to configure • Fluid interface • Usually has methods to to easily manipulate the domain Amir Barylko Advanced Design Patterns
  • 27. public class When_adding_a_an_invalid_extra_frame { [Test] public void Should_throw_an_exception() { // arrange 10.Times(() => this.GameBuilder.AddFrame(5, 4)); var game = this.GameBuilder.Build(); // act & assert new Action(() => game.Roll(8)).Should().Throw(); } } http://orthocoders.com/2011/09/05/the-bowling-game-kata-first-attempt/ Amir Barylko Advanced Design Patterns
  • 28. Amir Barylko Advanced Design Patterns
  • 29. VISITOR • Ability to traverse (visit) a object structure • Different visitors may produce different results • Avoid littering the classes with particular operations Amir Barylko Advanced Design Patterns
  • 31. NULL OBJECT • Represent “null” with an actual instance • Provides default functionality • Clear semantics of “null” for that domain Amir Barylko Advanced Design Patterns
  • 32. class animal { public: virtual void make_sound() = 0; }; class dog : public animal { void make_sound() { cout << "woof!" << endl; } }; class null_animal : public animal { void make_sound() { } }; http://en.wikipedia.org/wiki/Null_Object_pattern Amir Barylko Advanced Design Patterns
  • 33. FACTORY • Creates instances by request • More flexible than Singleton • Can be configured to create different families of objects • IoC containers are closely related • Can be implemented dynamic based on interfaces • Can be used also to release “resource” when not needed Amir Barylko Advanced Design Patterns
  • 34. interface GUIFactory { public Button createButton(); } class WinFactory implements GUIFactory { public Button createButton() { return new WinButton(); } } class OSXFactory implements GUIFactory { public Button createButton() { return new OSXButton(); } } interface Button { public void paint(); } http://en.wikipedia.org/wiki/Abstract_factory_pattern Amir Barylko Advanced Design Patterns
  • 35. STRATEGY • Abstracts the algorithm to solve a particular problem • Can be configured dynamically • Are interchangeable Amir Barylko Advanced Design Patterns
  • 37. DATA TRANSFER OBJECT • Simplifies information transfer across services • Can be optimized • Easy to understand Amir Barylko Advanced Design Patterns
  • 39. PAGE OBJECT • Abstract web pages functionality to be used usually in testing • Each page can be reused • Changes in the page impact only the implementation, not the clients Amir Barylko Advanced Design Patterns
  • 40. public class LoginPage {     public HomePage loginAs(String username, String password) {         // ... clever magic happens here     }         public LoginPage loginWithError(String username, String password) {         //  ... failed login here, maybe because // one or both of the username and password are wrong     }         public String getErrorMessage() {         // So we can verify that the correct error is shown     } } http://code.google.com/p/selenium/wiki/PageObjects Amir Barylko Advanced Design Patterns
  • 41. QUESTIONS? Amir Barylko Advanced Design Patterns
  • 42. RESOURCES • Email: amir@barylko.com, @abarylko • Slides: http://www.orthocoders.com/presentations • Patterns: Each pattern example has a link Amir Barylko Advanced Design Patterns
  • 43. RESOURCES II Amir Barylko Advanced Desing Patterns
  • 44. RESOURCES III Amir Barylko Advanced Desing Patterns
  • 45. CLOJURE TRAINING • When: Nov 6, 7 & 8 • More info: http://www.maventhought.com • Goal: LearnClojure and functional programming with real hands on examples Amir Barylko Advanced Desing Patterns