1. How I Learned To Apply Design Patterns Andy Maleh Obtiva Corp.
2. Outline What Are Design Patterns? Gang of Four Design Patterns GRASP Patterns Learning Process Example
3. What Are Design Patterns? Reusable solutions to common problems encountered at the software design level of abstraction. A pattern usually consists of: Name Problem Solution Consequences
4. Gang of Four Design Patterns Strategy State Decorator Proxy Abstract Factory Factory Method Chain of Responsibility Visitor???
5. GRASP Patterns General Responsibility Assignment Software Patterns Appeared in the book "Applying UML and Patterns" by Craig Larman Provide the underpinnings of Object Oriented Design Help explain the benefits of most Gang of Four design patterns as well as how they were arrived to Contemplated collectively instead of one at a time
6. GRASP Patterns Creator Information Expert Controller Low Coupling High Cohesion Polymorphism Pure Fabrication Indirection Protected Variations
7. Responsibility Driven Design Break requirements into use-cases Come up with scenarios for use-cases Figure out responsibilities for each step in a scenario Assign responsibilities to objects based on Object Oriented Design principles NOTE: the methodology is applied vertically in thin slices when following an Agile process
8. Learning Process Study design patterns with genuine interest to deeply understand them and recognize when applying them would reap benefits in real-world scenarios. Look for every opportunity to apply them to slowly develop a sense of smell for when patterns can be applied. Learn to recognize when a design pattern is absolutely necessary and helpful and when it is just over-engineering.
9. Example – Order Submission Requirements: When an order is first created, it is not ready for on-line submission as it is missing required information. An order becomes ready for submission once filled in with required information. A pending order is an order that was interrupted amidst on-line submission. Once an order is submitted, it cannot be edited and resubmitted.
11. Example – Order Submission Design: Each order state is represented with a state object Not Ready Ready Pending Submitted View observes order to update edit and submit button enablements
13. Example – Order Submission GRASP Patterns: Polymorphism Order States handling behavior polymorphically Indirection Observers provide indirect coupling to order state Protected Variations Order is protected from state variations Low Coupling Order has low coupling to behavior variation per state View has low coupling to Order via observers
14. Example – Order Submission Benefits: Order behavior variation across states is clarified Order behavior is easily maintainable in different classes No complicated if/else conditionals
15. Review What Are Design Patterns? Gang of Four Design Patterns GRASP Patterns Learning Process Example
17. References Design Patterns: Elements of Reusable Object-Oriented Software Authors: Gang of Four ISBN-13: 978-0201633610 Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development Author: Craig Larman ISBN-13: 978-0131489066 Recommended Chapters (17, 25, 26) Object Design: Roles, Responsibilities, and Collaborations Author: Rebecca Wirfs-Brock ISBN-13: 978-0201379433 Elephant Carpaccio Author: Alistair Cockburn URL: http://alistair.cockburn.us/Elephant+carpaccio#discussion
18. Contact Presenter: Andy Maleh Email: andy at obtiva dot com Twitter: AndyMaleh Blog: http://andymaleh.blogspot.com