how i learned to apply design patterns

18
How I Learned To Apply Design Patterns Andy Maleh Obtiva Corp.

Upload: andymaleh

Post on 12-May-2015

8.004 views

Category:

Technology


4 download

DESCRIPTION

A presentation on how I learned to apply design patterns in software development and the additional principles/guidelines that helped along the way.

TRANSCRIPT

Page 1: How I Learned To Apply Design Patterns

How I Learned To Apply Design Patterns

Andy MalehObtiva Corp.

Page 2: How I Learned To Apply Design Patterns

Outline What Are Design Patterns?

Gang of Four Design Patterns

GRASP Patterns

Learning Process

Example

Page 3: How I Learned To Apply Design Patterns

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

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

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

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

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

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

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

Example – Order Submission

Order State Diagram:

Page 11: How I Learned To Apply Design Patterns

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

Example – Order Submission

Design Patterns: State Observer

Page 13: How I Learned To Apply Design Patterns

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

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

Review What Are Design Patterns?

Gang of Four Design Patterns

GRASP Patterns

Learning Process

Example

Page 16: How I Learned To Apply Design Patterns

???

Page 17: How I Learned To Apply Design Patterns

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

Contact Presenter: Andy Maleh

Email: andy at obtiva dot com

Twitter: AndyMaleh

Blog: http://andymaleh.blogspot.com