Upload
andymaleh
View
8.004
Download
4
Tags:
Embed Size (px)
DESCRIPTION
A presentation on how I learned to apply design patterns in software development and the additional principles/guidelines that helped along the way.
Citation preview
How I Learned To Apply Design Patterns
Andy MalehObtiva Corp.
Outline What Are Design Patterns?
Gang of Four Design Patterns
GRASP Patterns
Learning Process
Example
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
Gang of Four Design Patterns
Strategy
State
Decorator
Proxy
Abstract Factory
Factory Method
Chain of Responsibility
Visitor???
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
GRASP Patterns Creator
Information Expert
Controller
Low Coupling
High Cohesion
Polymorphism
Pure Fabrication
Indirection
Protected Variations
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
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.
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.
Example – Order Submission
Order State Diagram:
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
Example – Order Submission
Design Patterns: State Observer
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
Example – Order Submission
Benefits: Order behavior variation across states is
clarified Order behavior is easily maintainable in
different classes No complicated if/else conditionals
Review What Are Design Patterns?
Gang of Four Design Patterns
GRASP Patterns
Learning Process
Example
???
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
Contact Presenter: Andy Maleh
Email: andy at obtiva dot com
Twitter: AndyMaleh
Blog: http://andymaleh.blogspot.com