Intro to Obj-C Design Patterns or Or how I learned to be less bad
How I Learned To Apply Design Patterns
-
Upload
andymaleh -
Category
Technology
-
view
8.002 -
download
4
description
Transcript of How I Learned To Apply Design Patterns
![Page 1: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/1.jpg)
How I Learned To Apply Design Patterns
Andy MalehObtiva Corp.
![Page 2: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/2.jpg)
Outline What Are Design Patterns?
Gang of Four Design Patterns
GRASP Patterns
Learning Process
Example
![Page 3: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/3.jpg)
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
![Page 4: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/4.jpg)
Gang of Four Design Patterns
Strategy
State
Decorator
Proxy
Abstract Factory
Factory Method
Chain of Responsibility
Visitor???
![Page 5: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/5.jpg)
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
![Page 6: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/6.jpg)
GRASP Patterns Creator
Information Expert
Controller
Low Coupling
High Cohesion
Polymorphism
Pure Fabrication
Indirection
Protected Variations
![Page 7: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/7.jpg)
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
![Page 8: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/8.jpg)
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.
![Page 9: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/9.jpg)
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.
![Page 10: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/10.jpg)
Example – Order Submission
Order State Diagram:
![Page 11: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/11.jpg)
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
![Page 12: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/12.jpg)
Example – Order Submission
Design Patterns: State Observer
![Page 13: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/13.jpg)
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
![Page 14: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/14.jpg)
Example – Order Submission
Benefits: Order behavior variation across states is
clarified Order behavior is easily maintainable in
different classes No complicated if/else conditionals
![Page 15: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/15.jpg)
Review What Are Design Patterns?
Gang of Four Design Patterns
GRASP Patterns
Learning Process
Example
![Page 16: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/16.jpg)
???
![Page 17: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/17.jpg)
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
![Page 18: How I Learned To Apply Design Patterns](https://reader033.fdocuments.in/reader033/viewer/2022052619/55516270b4c9059f768b4fd6/html5/thumbnails/18.jpg)
Contact Presenter: Andy Maleh
Email: andy at obtiva dot com
Twitter: AndyMaleh
Blog: http://andymaleh.blogspot.com