Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Object Oriented Design Patterns

Object Oriented Design Patterns

Slides for the Code Slingers Object Oriented Design Patterns talk on 08/11/2016

Avatar for Josh Schanke

Josh Schanke

August 11, 2016

Other Decks in Technology

Transcript

  1. SYMPTOMS OF BAD ARCHITECTURE • Rigidity – Difficult to change

    • Fragility – Tendency to break in many places when 1 change is made • Immobility – An application contains parts that are useful to another system, but too risky to break out • Viscosity – Cases where the design of the software is hard to preserve. The hacky change is easier than the right change
  2. SOLID PRINCIPLES • Single Responsibility Principle • Open/Closed Principle •

    Liskov Substitution Principle • Interface Segregation Principle • Dependency Inversion Principle
  3. WHAT? WHY? • Common vocabulary to talk about different structures

    of code • Can be used in any OO language • Easily recognizable code structures even to someone with no knowledge of the program
  4. FAÇADE • Structural • Hides the complexity of an external

    system by providing simpler, easy to use methods to interact with the external system • Can reduce the number of dependencies in your code
  5. WHERE COULD WE USE THIS? • Combining many related many

    things into 1 interface • Making a horrible API easier to use
  6. ADAPTER • Structural • A single class designed to join

    functionalities of independent or incompatible interfaces
  7. WHERE COULD WE USE THIS? • Going from one stack

    to another • Separating legacy code from shiny new code
  8. STRATEGY • Behavioral • Defines a family of algorithms, encapsulates

    each one, and makes them interchangeable. • Improves readability by isolating behavior
  9. WHERE COULD WE USE THIS? • Anything where extensibility is

    desired • You need behavior to be decided at runtime • Validating data based on type, source, etc
  10. OBSERVER • Behavioral • Defines a one-to-many dependency between objects

    so that when one object changes state, all of its dependents are notified and updated automatically
  11. WHERE COULD WE USE THIS? • Anywhere you want to

    react to changes to something • Eventing systems • Knockout.js observables • MVC Views
  12. ITERATOR • Behavioral • A way to access elements of

    a collection object in a sequential manner without any need to know it’s underlying representation
  13. STATE • Behavioral • A way to change class behavior

    based on its state • State Machines
  14. FACTORY • Creational • Define an interface for creating an

    object, but let subclasses decide which class to instantiate
  15. ABSTRACT FACTORY • Creational • Factory of factories • Provides

    an interface which is responsible for creating a factory of related objects without explicitly specifying their classes
  16. TEMPLATE • Behavioral • Abstract class exposing defined ways(templates) to

    execute its methods. Subclasses can override behavior if necessary, but are invoked the same way
  17. COMPOSITE • Structural • Used when you need to treat

    a group of objects in a similar way as a single object • Usually composed as part of a tree structure
  18. SINGLETON • Creational • A class which is responsible for

    creating an object while making sure that only a single object gets created • Frequently misused
  19. COMMAND • Behavioral • A request is wrapped under an

    object as a command and pass to an invoker object. The invoker object finds an object that can handle this command and passes it to that object. • Allows requests to be encapsulated as objects
  20. USEFUL RESOURCES • Head First Design Patterns • Design Patterns:

    Elements of Reusable Object-Oriented Software • http://www.dofactory.com/net/design-patterns - C# focused • http://www.tutorialspoint.com/design_pattern - Java focused • http://www.mcdonaldland.info/files/designpatterns/designpatternscard.pdf • https://sourcemaking.com/design_patterns