SlideShare a Scribd company logo
1 of 24
Design Pattern Zoology

 Taxonomy and Field Guide of
  Common Design Patterns


                       Josh Adell <josh.adell@gmail.com>
                                               20120719
@josh_adell

• Software developer: PHP, Javascript, SQL
• http://www.dunnwell.com
• http://joshadell.com

• http://mojolive.com/profile/joshadell

• http://github.com/jadell/neo4jphp
• http://frostymug.herokuapp.com
Play Along



http://github.com/jadell/dpzoology
Coming Soon...

• What are design patterns?
• Why design patterns?
• Common design patterns with examples
Stages of OOP




     Larva
Stages of OOP




     Pupa
Stages of OOP




     Adult
Design Patterns Are

• General solutions to common problems
• Architectural templates
• Named approaches to code structure
Design Patterns Are Not

• Off-the-shelf solutions
• One-size-fits-all panacea
Anti-patterns

• Poorly or inappropriately used patterns
• Increase code complexity and/or fragility
Why use design patterns?

•   Proven solutions
•   Simplify code structure
•   Promote loose coupling, high cohesion
•   Enhance testing/testability


Design Patterns are where the power of OOP comes from
SOLID Principles

•   Single Responsibility
•   Open/Closed
•   Liskov Substitution
•   Interface Segregation
•   Dependency Inversion
Common Themes

•   Code to an Interface, not an Implementation
•   One class == one responsibility
•   Favor Compostion over Inheritance
•   Replace branching with polymorphism
•   Low coupling, high cohesion
Types of Patterns

• Architectural        • Code
  o Client-Server        o Adapter
  o Cloud                o Chain-of-Command
                         o Command
• Application            o Decorator
  o MVC                  o Delegate
  o Services             o Factory
  o Message Queue        o Flyweight
                         o Observer
• UX                     o Singleton
  o Call to Action       o Strategy
  o Progressive          o Visitor
    disclosure
Let's get started!
Strategy

•   Define a family of behaviors
•   Each behavior is accessed via a common interface
•   Client code doesn't care which behavior it uses
•   Behaviors can be shared across class hierarchies
Delegate

• Delegator passes a request to a helper (the delegate)
• Delegate handles request, passes result back
• Delegator passes result back to caller
Decorator

•   Add behaviors to a base object dynamically
•   Base decorator passes through unmodified
•   Decorators that modify requests or responses
•   Decorators wrap a base object or decorator
Chain-of-Responsibility

• Dispatcher calls a handler, that calls a handler...
• Each handler responsible for passing to next
• Stop when event is handled
Observer

• Publish-subscribe
• Broadcast an event, all observers catch and handle
• Broadcaster doesn't care about observers
Patterns derive from each other

• Delegate is based on Strategy
• CoR is a string of Delegates that call each other
• Decorator & Observer are CoR that always run to the end
Wrap Up

• More patterns out there: Command, Facade, Pool,
  Mediator, Visitor, Adapter
• Use this vocabulary during technical discussions
• Refactor spaghetti and long-winded code
• Decrease coupling, increase cohesion!
Good References

• http://www.oodesign.com
• Gang of Four - Gamma, Helm, Johnson, Vlissides
• Head-First Design Patterns
Questions?

More Related Content

Viewers also liked

Uses of computer in various fields of life
Uses of computer in various fields of lifeUses of computer in various fields of life
Uses of computer in various fields of lifeAftab Badshah
 
Uses of computers in education
Uses of computers in educationUses of computers in education
Uses of computers in educationMelanie Garay
 
Uses of computer
Uses of computerUses of computer
Uses of computera2zeenice
 
Uses of computer in various fields
Uses of computer in various fieldsUses of computer in various fields
Uses of computer in various fieldsDivyanshu Gupta
 
Uses of Computers in Education
Uses of Computers in EducationUses of Computers in Education
Uses of Computers in EducationAllana Delgado
 

Viewers also liked (7)

Uses of Computer
Uses of ComputerUses of Computer
Uses of Computer
 
Uses of computer
Uses of computer Uses of computer
Uses of computer
 
Uses of computer in various fields of life
Uses of computer in various fields of lifeUses of computer in various fields of life
Uses of computer in various fields of life
 
Uses of computers in education
Uses of computers in educationUses of computers in education
Uses of computers in education
 
Uses of computer
Uses of computerUses of computer
Uses of computer
 
Uses of computer in various fields
Uses of computer in various fieldsUses of computer in various fields
Uses of computer in various fields
 
Uses of Computers in Education
Uses of Computers in EducationUses of Computers in Education
Uses of Computers in Education
 

Similar to Design Pattern Zoology

Clean code presentation
Clean code presentationClean code presentation
Clean code presentationBhavin Gandhi
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patternsRahul Singh
 
Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"GlobalLogic Ukraine
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Codersebbe
 
2009 training - tim m - object oriented programming
2009   training - tim m - object oriented programming2009   training - tim m - object oriented programming
2009 training - tim m - object oriented programmingTim Mahy
 
TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleNoam Kfir
 
SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"Inhacking
 
[DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
 [DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a... [DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
[DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...DevDay.org
 
Software Engineering - Trends & Industry Practices
Software Engineering - Trends & Industry PracticesSoftware Engineering - Trends & Industry Practices
Software Engineering - Trends & Industry PracticesAlfred Jett Grandeza
 
Design Patterns .Net
Design Patterns .NetDesign Patterns .Net
Design Patterns .NetHariom Shah
 
Improving the Design of Existing Software
Improving the Design of Existing SoftwareImproving the Design of Existing Software
Improving the Design of Existing SoftwareSteven Smith
 
Scala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and qualityScala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and qualityJaime Jorge
 
"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design PrinciplesSerhiy Oplakanets
 
Evolutionary Design - NewCrafts Paris 18 May 2018
Evolutionary Design - NewCrafts Paris 18 May 2018Evolutionary Design - NewCrafts Paris 18 May 2018
Evolutionary Design - NewCrafts Paris 18 May 2018Adi Bolboaca
 
Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)Heartin Jacob
 
Design patterns and MV
Design patterns and MVDesign patterns and MV
Design patterns and MVSway Wang
 
Deployment is the new build
Deployment is the new buildDeployment is the new build
Deployment is the new buildAndrew Phillips
 

Similar to Design Pattern Zoology (20)

Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patterns
 
Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 
2009 training - tim m - object oriented programming
2009   training - tim m - object oriented programming2009   training - tim m - object oriented programming
2009 training - tim m - object oriented programming
 
TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black Hole
 
SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"
 
Alex Theedom Java ee revisits design patterns
Alex Theedom	Java ee revisits design patternsAlex Theedom	Java ee revisits design patterns
Alex Theedom Java ee revisits design patterns
 
[DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
 [DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a... [DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
[DevDay 2016] Design Pattern at a glance - Speaker: Tuan Do – Scrum Master a...
 
Software Engineering - Trends & Industry Practices
Software Engineering - Trends & Industry PracticesSoftware Engineering - Trends & Industry Practices
Software Engineering - Trends & Industry Practices
 
Design Patterns .Net
Design Patterns .NetDesign Patterns .Net
Design Patterns .Net
 
Improving the Design of Existing Software
Improving the Design of Existing SoftwareImproving the Design of Existing Software
Improving the Design of Existing Software
 
Scala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and qualityScala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and quality
 
"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles
 
Evolutionary Design - NewCrafts Paris 18 May 2018
Evolutionary Design - NewCrafts Paris 18 May 2018Evolutionary Design - NewCrafts Paris 18 May 2018
Evolutionary Design - NewCrafts Paris 18 May 2018
 
Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)
 
Design patterns and MV
Design patterns and MVDesign patterns and MV
Design patterns and MV
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Deployment is the new build
Deployment is the new buildDeployment is the new build
Deployment is the new build
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
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
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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)
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
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
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
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
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

Design Pattern Zoology

  • 1. Design Pattern Zoology Taxonomy and Field Guide of Common Design Patterns Josh Adell <josh.adell@gmail.com> 20120719
  • 2. @josh_adell • Software developer: PHP, Javascript, SQL • http://www.dunnwell.com • http://joshadell.com • http://mojolive.com/profile/joshadell • http://github.com/jadell/neo4jphp • http://frostymug.herokuapp.com
  • 4. Coming Soon... • What are design patterns? • Why design patterns? • Common design patterns with examples
  • 8. Design Patterns Are • General solutions to common problems • Architectural templates • Named approaches to code structure
  • 9. Design Patterns Are Not • Off-the-shelf solutions • One-size-fits-all panacea
  • 10. Anti-patterns • Poorly or inappropriately used patterns • Increase code complexity and/or fragility
  • 11. Why use design patterns? • Proven solutions • Simplify code structure • Promote loose coupling, high cohesion • Enhance testing/testability Design Patterns are where the power of OOP comes from
  • 12. SOLID Principles • Single Responsibility • Open/Closed • Liskov Substitution • Interface Segregation • Dependency Inversion
  • 13. Common Themes • Code to an Interface, not an Implementation • One class == one responsibility • Favor Compostion over Inheritance • Replace branching with polymorphism • Low coupling, high cohesion
  • 14. Types of Patterns • Architectural • Code o Client-Server o Adapter o Cloud o Chain-of-Command o Command • Application o Decorator o MVC o Delegate o Services o Factory o Message Queue o Flyweight o Observer • UX o Singleton o Call to Action o Strategy o Progressive o Visitor disclosure
  • 16. Strategy • Define a family of behaviors • Each behavior is accessed via a common interface • Client code doesn't care which behavior it uses • Behaviors can be shared across class hierarchies
  • 17. Delegate • Delegator passes a request to a helper (the delegate) • Delegate handles request, passes result back • Delegator passes result back to caller
  • 18. Decorator • Add behaviors to a base object dynamically • Base decorator passes through unmodified • Decorators that modify requests or responses • Decorators wrap a base object or decorator
  • 19. Chain-of-Responsibility • Dispatcher calls a handler, that calls a handler... • Each handler responsible for passing to next • Stop when event is handled
  • 20. Observer • Publish-subscribe • Broadcast an event, all observers catch and handle • Broadcaster doesn't care about observers
  • 21. Patterns derive from each other • Delegate is based on Strategy • CoR is a string of Delegates that call each other • Decorator & Observer are CoR that always run to the end
  • 22. Wrap Up • More patterns out there: Command, Facade, Pool, Mediator, Visitor, Adapter • Use this vocabulary during technical discussions • Refactor spaghetti and long-winded code • Decrease coupling, increase cohesion!
  • 23. Good References • http://www.oodesign.com • Gang of Four - Gamma, Helm, Johnson, Vlissides • Head-First Design Patterns

Editor's Notes

  1. * Use classes to hold data structures together * Logic is procedural * Ask for data, but operates on data outside of where the data resides * Rules are hard-coded * Stage 0: Egg, all code is procedural, global state, arrays/scalars for data
  2. * Use classes to hold data structures together, and provide behaviors for maintaining the data * Ensure data integrity * Most logic is still procedural, hard-coded
  3. * Use classes to hold data structures together, and provide behaviors for maintaining the data * Objects also represent behavior, not just data * Logic comes from the interaction of objects via contracts/interfaces * Behavior emerges from interactions, not predetermined rules
  4. * Gang of Four * Best practices
  5. * No one-size-fits-all * Require forethought to determine which pattern is appropriate * No excuse for poorly designed code
  6. * pre-mature optimization * misunderstood refactoring * Any pattern taken to an extreme can become an anti-pattern
  7. * Provide a common vocabulary for discussing architecture * Simplicity through code re-use * Coupling: unnecessary linking of one component to another.  Hard to change one without changing the other. * Solve by coding to an interface! * Cohesion: component parts fit together in logical, narrowly-defined ways. * One class or method = one responsibility
  8. * An object has only one responsibility * Objects are open for extension but closed for modification * Any entity can be replaced by a sub-type of that entity (or one that meets the same contract) * Many specific interfaces are better than one general interface * Depend on contracts/interfaces, not concrete instantiations
  9. * themes that underly all the design patterns * at least the ones we&apos;re going to talk about * De-coupling * Tight cohesion * small classes and methods are easier to work with than large ones * easier to debug * easier to test! * Dependency Injection * Objects create objects or do business logic, not both
  10. * architectural: how systems fit together, interact * application: how code systems are divided, layered * Code: how code logic is divided, behaves and interacts * Common to all: how bits of a system talk to each other, pass information (code, servers, users) * You&apos;ve probably used these patterns without knowing it, or knowing their names
  11. * Next slides:    * Introduce a pattern     * Concept     * When to use   * Show an example
  12. * Very common pattern, can be seen as the basis for many other patterns * If you learn only one, learn this one! * Each behavior is its own class * Behavior can be selected and changed at runtime * Behavior not tied to client * Composition over inheritance! * Unit testing tip: pass in a mock strategy to test that client calls it correctly Use when: * behavior needed across multiple classes/heirarchies * behavior needs to change dynamically
  13. * Strategy&apos;s brother * Code sample-1 * Code sample-2 Use when: * Single object has a wide interface
  14. * Classis example is ordering pizza, coffee, car options * Notice that no decorator knows if it&apos;s talking to a decorator or the base object. * Can unit test decorator by passing in a mock base, know it will work on any decorator or base in the family * Code sample-3 Use when: * Behaviors are conditional * Behaviors are chained * Order (probably) doesn&apos;t matter
  15. * Also see this called &amp;quot;Chain of Command&amp;quot; * I used to call it this, but saw people get it confused with the actual &amp;quot;Command&amp;quot; pattern * Dispatcher only knows the first handler * Dispatcher doesn&apos;t care who handled the event, only that it was or was not handled * Handlers handle their own errors internally, should not affect dispatcher or any other handler * Code sample-4 * Code sample-5 Use when: * More than one way to handle an event * How it&apos;s handled doesn&apos;t matter; just that it is handled or not
  16. * Broadcast is an event and any associated parameters * Subscribers can request only to hear about specific events * Subscribers must cleanup after themselves, handle their own failure * Decouples generation of event from its handling * Doctrine * Javascript in general * Code sample-6 Use when: * Event triggers many independent behaviors * Event generator doesn&apos;t care about results * State changes need to be known by many objects
  17. * Said before, if you only learn one, learn Strategy. * All other can be derived from it