Design Patterns

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    4 Favorites

    Design Patterns - Presentation Transcript

    1. Design Patterns
      • Part One
      • Part Two
    2. Part 1
      • What design is
      • What it's not
      • Why patterns?
    3. (Part 2 is about Patterns en détail)
    4. What design is
      • Process
        • Thought
        • Methodology
        • Discussion
      • Attitude
        • Simplicity
        • Finding solutions for a given problem
    5. What it's not
      • Enforcing schemas
      • Dictating solutions
      • Finding problems for a given solution
      • One Solution Fits All
    6. Why patterns?
      • reuse
        • similar problems occur over and over again – just reuse the code
      • separation
        • when you separate concerns you should have a single point of failure for everything anyway
    7. Why patterns?
      • reuse
        • similar problems occur over and over again – with small but significant differences between one and the other
      • separation
        • separate those parts of the solution that change from those that stay the same
    8. Why patterns?
      • reuse
        • a pattern once identified can be used when ever you encounter a similar problem
      • separation
        • patterns are ideas and practices, not classes and methods
    9. Part 2 Patterns en détail
    10. What have we?
      • the Template
      • the Strategy
      • the Observer
      • the Composite
      • the Iterator
      • the Command
      • the Adapter
      • the Proxy
      • the Decorator
      • the Singleton
      • the Factory
      • the Builder
      • the Interpreter
      • the DSL
      • the Meta
      • the COC
    11. Quite a bunch! Let's start with the classic patterns.
    12. Template (Method)
      • abstract class/module
      • several virtual methods
      • one method that runs the virtual methods in a certain order
      • concrete classes that implement the virtual methods
      • a call to the template method on the concrete class
    13. Template (Method)
      • When to use?
        • there is a certain sequence of actions done ever again but how the actions executed differs from case to case
      • Examples
        • Tests
          • setup()
          • test_xy()
          • teardown()
        • Processors
          • some object loading
          • process_object()
    14. Strategy
      • context
        • a property containing the strategy
      • abstract strategy
        • a virtual method for doing the strategy
      • concrete strategies
        • the concrete strategy method
        • all the methods need to accomplish the task
    15. Strategy
      • When to use?
        • There is some action that needs to be done in several different ways which differ far beyond what a Template covers
      • Examples
        • Processors
          • on_message()
        • Miners
          • run()
    16. Observer
      • abstract subject
        • observers as property
        • logic to add/remove/inform observers
      • observer
        • update method
      • concrete subject
        • business logic including informing observers
    17. Observers
      • When to use?
        • You want to be informed when some state in the subject changes and react to that.
      • Examples
        • ActiveRecord::Observer
    18. Composite
      • abstract component
        • virtual methods
      • concrete component 'leaf'
        • concrete methods
      • concrete component 'composite'
        • property for subcomponents
        • concrete methods that delegate to the subcomponents
    19. Composite
      • When to use?
        • You want to treat some object the same, no matter how complex the operation is you want to have done, but you want to model the operation in as small steps as necessary.
      • Example
        • GUIs like FXRuby
          • windows, frames, buttons, labels
    20. Iterator
      • internal
        • method that yields a block on every of the object's properties/elements
      • external
        • an object keeps track of which property of another element you are currently reading and if there are more to read
    21. Iterator
      • When to use?
        • general
          • you need access (in order) to each property of an object to do something with it
        • internal
          • you want the object to be able to expose its properties on its own
        • external
          • you want to decouple the exposition from the object, for use independent of the property container
      • Examples
        • Enumerable module
    22. Command
      • abstract command class
        • virtual methods
      • concrete command classes
        • concrete methods
    23. Command
      • When to use?
        • You need something to be done without care of how it is done. You may even delay the operation, aggregate actions or provide ways to undo something.
      • Examples
        • Background#do
        • ActsAsPublished
          • bulk updates
        • Migrations
          • up/down
    24. Adapter
      • client
        • knows some target
          • target's methods
      • target (adapter)
        • adaptee
          • adaptee's methods
        • methods that call adaptee's methods
      • or
        • redefined adaptee class
          • happens...
    25. Adapter
      • When to use?
        • When ever you want you client target to access one of some server classes which have completely different interfaces.
      • Examples
        • ActiveRecord::Adapter::XY
        • abstract search
    26. Proxy
      • abstract service
        • virtual method
      • concrete service
        • concrete method
      • service proxy (< abstract service)
        • property for the concrete service
        • proxy method calling the concrete method
    27. Proxy
      • When to use?
        • protection
          • making sure some state is checked before the methods get loaded
        • remoting
          • your real service is over the net or somewhere and you don't want the client to bother manage the connection
        • virtualization
          • you want the concrete service to be loaded first when some method is called on him, not on initialization of the service
      • Example: DRb
    28. Some thought on a Proxy
      • virtual proxy means some object is loaded only later
      • observers load all our model code on initialization of the webserver
      • why not warp the models in a proxy?
      • problem: we would perhaps have to use the proxy everywhere
      • perhaps a Command could help out catching the observe command and being run by the Model on load
    29. Decorator
      • abstract component
        • virtual methods
      • concrete component
        • concrete methods
      • decorator component
        • component property
        • new methods
        • methods calling the new methods and then the method on the property component
    30. Decorator
      • When to use?
        • On occasion you want something to be done to the parameter before the actual method is called or you want some other things to be executed along with the original method.
      • Examples
        • Acts_as_...
        • alias_method_chain
    31. Singleton
      • one class
        • one instance
          • a private initialize method
          • other methods
      • alternatively a module or a class
        • methods
    32. Singleton
      • When to use?
        • You want something to be loaded just once, like a config file, a connection object or the like.
      • Examples
        • the communipediaApi configuration
          • Class style singleton
        • the sitemap
          • instance singleton
    33. Factory
      • abstract factory class
        • virtual object initialization methods
      • concrete factory class
        • concrete methods for initializing several objects
    34. Factory
      • When to use?
        • In a certain place you need to be handed instances of different objects depending on some criteria.
      • Examples
        • Campaign
          • new() loads a certain campaign type depending on what you tell it
    35. Builder
      • product class
        • properties
      • builder class
        • property product
        • methods to set the products properties
        • additional methods
      • director
        • property builder
    36. Builder
      • When to use?
        • You need objects only built in a certain state but you don't what to have the object bother enforcing the right state.
      • Examples
        • ActiveRecord models
          • validations
          • data is built to fit the chosen DB
    37. Interpreter
      • client
        • properties expressions
        • property context
      • abstract expression
        • virtual interpret method
      • terminal expression
        • interpret method
      • nonterminal expression
        • properties sub expressions
        • interpret method
    38. Interpreter
      • When to use?
        • You want to introduce some specific expression language to a certain task who's code you need to execute.
      • Examples
        • Ruby
          • itself (which is too complex for the pattern actually)
        • regex
    39. That's it. Not really. But so much for the classic patterns.
    40. Ruby patterns. Now for some more ruby specific patterns.
    41. Domain Specific Language
      • file filled with (syntactically) correct ruby code
      • loader class
        • methods used as keywords in the file
    42. Domain Specific Language
      • When to use?
        • You want non-programmers to define e.g. behaviors of something. You like the ease of defining config files without needing an interpreter to load it again.
      • Examples
        • campaign
          • the chain methods could be used as DSL
    43. Meta (Programming)
      • meta class
        • methods
      • classes defined by the meta class methods
        • methods definded by the meta class methods
    44. Meta (Programming)
      • When to use?
        • You need objects with certain behaviour or set of methods depending on some conditions but you don't want to define every possible combination in a separate class.
      • Examples
        • ActsAsSolr
        • pick a file...
    45. Convention over Configuration
      • classes
        • intelligent defaults
      • configurations
        • items that override the defaults
    46. Convention over Configuration
      • When to use?
        • You want a behavior that you can set in certain ways and you know one that fits most of the time or serves as fallback.
      • Examples
        • Rails::*
        • search_backend
    47. That's it. (finally)

    + imedo.deimedo.de, 2 years ago

    custom

    1414 views, 4 favs, 1 embeds more stats

    A short overview about the design patterns describe more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1414
      • 1404 on SlideShare
      • 10 from embeds
    • Comments 0
    • Favorites 4
    • Downloads 74
    Most viewed embeds
    • 10 views on http://devblog.imedo.de

    more

    All embeds
    • 10 views on http://devblog.imedo.de

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories