0
AMIR BARYLKO                  ADVANCED               DESIGN PATTERNSAmir Barylko               Advanced Design Patterns
WHO AM I?  • Software     quality expert  • Architect  • Developer  • Mentor  • Great      cook  • The    one who’s entert...
RESOURCES  • Email: amir@barylko.com  • Twitter: @abarylko  • Blog: http://www.orthocoders.com  • Materials: http://www.or...
PATTERNS                    What are they?                What are anti-patterns?               Which patterns do you use?...
WHAT ARE PATTERNS?  •Software         design Recipe  •or     Solution  •Should         be reusable  •Should         be gen...
ANTI-PATTERNS  •   More patterns != better design  •   No cookie cutter  •   Anti Patterns : Patterns to identify failure ...
WHICH PATTERNS                   DO YOU USE?  • Fill   here with your patterns:Amir Barylko                          Advan...
ADVANCED PATTERNS                     Let’s vote!Amir Barylko                       Advanced Design Patterns
SOME PATTERNS...  •   Chain of resp.     •   List            •   Composite                             Comprehension  •   ...
CHAIN OF RESPONSIBILITY  • More   than one object may handle a request, and the handler    isnt known a priori.  • The    ...
Amir Barylko   Advanced Design Patterns
PROXY  • Avoid       creating the object until needed  • Provides      a placeholder for additional functionality  • Very ...
GOF
ACTIVERECORD  • Isa Domain Model where classes match very closely the    database structure  • Each table is mapped to cla...
create_table   "movies", :force => true do |t|    t.string     "title"    t.string     "description"    t.datetime   "crea...
REPOSITORY  • Mediator        between domain and storage  • Acts       like a collection of items  • Supports        queri...
http://martinfowler.com/eaaCatalog/repository.htmlAmir Barylko                                     Advanced Design Patterns
EVENT AGGREGATOR  • Manage      events using a subscribe / publish mechanism  • Isolates   subscribers from publishers  • ...
Channel events  from multiple  objects into a  single object to  s i m p l i f y  registration for  clientsAmir Barylko   ...
MT COMMONSAmir Barylko                Advanced Design Patterns
EVENT SOURCING  • Register     all changes in the application using events  • Event      should be persisted  • Complete  ...
http://martinfowler.com/eaaDev/EventSourcing.htmlAmir Barylko                                    Advanced Design Patterns
Amir Barylko   Advanced Design Patterns
LIST COMPREHENSION  • Syntax      Construct in languages  • Describe      properties for the list (sequence)  • Filter  • ...
LANGUAGE COMPARISON  • Scala   for (x <- Stream.from(0); if x*x > 3) yield 2*x  • LINQ   var range = Enumerable.Range(0..2...
OBJECT MOTHER / BUILDER  • Creates       an object for testing (or other) purposes  • Assumes        defaults  • Easy    t...
public class When_adding_a_an_invalid_extra_frame   {       [Test]       public void Should_throw_an_exception()       {  ...
Amir Barylko   Advanced Design Patterns
VISITOR  • Ability    to traverse (visit) a object structure  • Different     visitors may produce different results  • Av...
http://en.wikipedia.org/wiki/Visitor_pattern#DiagramAmir Barylko                                     Advanced Design Patte...
NULL OBJECT  • Represent “null” with      an actual instance  • Provides      default functionality  • Clear      semantic...
class animal {    public:       virtual void make_sound() = 0;    };    class dog : public animal {       void make_sound(...
FACTORY  • Creates      instances by request  • More       flexible than Singleton  • Can    be configured to create differe...
interface GUIFactory {       public Button createButton();   }   class WinFactory implements GUIFactory {       public But...
STRATEGY  • Abstracts   the algorithm to solve a particular problem  • Can    be configured dynamically  • Are    interchan...
http://orthocoders.com/2010/04/Amir Barylko                                     Advanced Design Patterns
DATA TRANSFER OBJECT  • Simplifies   information transfer across services  • Can    be optimized  • Easy   to understandAmi...
http://martinfowler.com/eaaCatalog/dataTransferObject.htmlAmir Barylko                                 Advanced Design Pat...
PAGE OBJECT  • Abstract      web pages functionality to be used usually in testing  • Each       page can be reused  • Cha...
public class LoginPage {     public HomePage loginAs(String username, String password) {         // ... clever magic happe...
QUESTIONS?Amir Barylko                Advanced Design Patterns
RESOURCES  • Email: amir@barylko.com, @abarylko  • Slides: http://www.orthocoders.com/presentations  • Patterns: Each   pa...
RESOURCES IIAmir Barylko                  Advanced Desing Patterns
RESOURCES IIIAmir Barylko                   Advanced Desing Patterns
CLOJURE TRAINING  • When: Nov       6, 7 & 8  • More       info: http://www.maventhought.com  • Goal: LearnClojure and fun...
Upcoming SlideShare
Loading in...5
×

sdec11-Advanced-design-patterns

960

Published on

Presentation done at SDEC about design patterns and anti-patterns

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
960
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
27
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "sdec11-Advanced-design-patterns"

  1. 1. AMIR BARYLKO ADVANCED DESIGN PATTERNSAmir Barylko Advanced Design Patterns
  2. 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. 3. RESOURCES • Email: amir@barylko.com • Twitter: @abarylko • Blog: http://www.orthocoders.com • Materials: http://www.orthocoders.com/presentationsAmir Barylko Advanced Desing Patterns
  4. 4. PATTERNS What are they? What are anti-patterns? Which patterns do you use?Amir Barylko Advanced Design Patterns
  5. 5. WHAT ARE PATTERNS? •Software design Recipe •or Solution •Should be reusable •Should be general •No particular languageAmir Barylko Advanced Design Patterns
  6. 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. 7. WHICH PATTERNS DO YOU USE? • Fill here with your patterns:Amir Barylko Advanced Design Patterns
  8. 8. ADVANCED PATTERNS Let’s vote!Amir Barylko Advanced Design Patterns
  9. 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 • CommandAmir Barylko Advanced Desing Patterns
  10. 10. CHAIN OF RESPONSIBILITY • More than one object may handle a request, and the handler isnt 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 dynamicallyAmir Barylko Advanced Design Patterns
  11. 11. Amir Barylko Advanced Design Patterns
  12. 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. 13. GOF
  14. 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 classesAmir Barylko Advanced Design Patterns
  15. 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 endAmir Barylko Advanced Design Patterns
  16. 16. REPOSITORY • Mediator between domain and storage • Acts like a collection of items • Supports queries • Abstraction of the storageAmir Barylko Advanced Design Patterns
  17. 17. http://martinfowler.com/eaaCatalog/repository.htmlAmir Barylko Advanced Design Patterns
  18. 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 objectsAmir Barylko Advanced Design Patterns
  19. 19. Channel events from multiple objects into a single object to s i m p l i f y registration for clientsAmir Barylko Advanced Design Patterns
  20. 20. MT COMMONSAmir Barylko Advanced Design Patterns
  21. 21. EVENT SOURCING • Register all changes in the application using events • Event should be persisted • Complete Rebuild • Temporal Query • Event ReplayAmir Barylko Advanced Design Patterns
  22. 22. http://martinfowler.com/eaaDev/EventSourcing.htmlAmir Barylko Advanced Design Patterns
  23. 23. Amir Barylko Advanced Design Patterns
  24. 24. LIST COMPREHENSION • Syntax Construct in languages • Describe properties for the list (sequence) • Filter • Mapping • Same idea for Set or Dictionary comprehensionAmir Barylko Advanced Design Patterns
  25. 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. 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 domainAmir Barylko Advanced Design Patterns
  27. 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. 28. Amir Barylko Advanced Design Patterns
  29. 29. VISITOR • Ability to traverse (visit) a object structure • Different visitors may produce different results • Avoid littering the classes with particular operationsAmir Barylko Advanced Design Patterns
  30. 30. http://en.wikipedia.org/wiki/Visitor_pattern#DiagramAmir Barylko Advanced Design Patterns
  31. 31. NULL OBJECT • Represent “null” with an actual instance • Provides default functionality • Clear semantics of “null” for that domainAmir Barylko Advanced Design Patterns
  32. 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_patternAmir Barylko Advanced Design Patterns
  33. 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 neededAmir Barylko Advanced Design Patterns
  34. 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_patternAmir Barylko Advanced Design Patterns
  35. 35. STRATEGY • Abstracts the algorithm to solve a particular problem • Can be configured dynamically • Are interchangeableAmir Barylko Advanced Design Patterns
  36. 36. http://orthocoders.com/2010/04/Amir Barylko Advanced Design Patterns
  37. 37. DATA TRANSFER OBJECT • Simplifies information transfer across services • Can be optimized • Easy to understandAmir Barylko Advanced Design Patterns
  38. 38. http://martinfowler.com/eaaCatalog/dataTransferObject.htmlAmir Barylko Advanced Design Patterns
  39. 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 clientsAmir Barylko Advanced Design Patterns
  40. 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/PageObjectsAmir Barylko Advanced Design Patterns
  41. 41. QUESTIONS?Amir Barylko Advanced Design Patterns
  42. 42. RESOURCES • Email: amir@barylko.com, @abarylko • Slides: http://www.orthocoders.com/presentations • Patterns: Each pattern example has a linkAmir Barylko Advanced Design Patterns
  43. 43. RESOURCES IIAmir Barylko Advanced Desing Patterns
  44. 44. RESOURCES IIIAmir Barylko Advanced Desing Patterns
  45. 45. CLOJURE TRAINING • When: Nov 6, 7 & 8 • More info: http://www.maventhought.com • Goal: LearnClojure and functional programming with real hands on examplesAmir Barylko Advanced Desing Patterns
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×