63
I <3 Patterns Matt Ruma (@mattruma) Ann Arbor Day of .NET, October 29, 2011

I Love Patterns

Embed Size (px)

DESCRIPTION

Patterns can be found in all areas of your life, from creating grocery lists to crafting robust software applications. This session will introduce you to the concept of patterns, their history and benefits. We'll look at some different uses of patterns in crafting software applications, including design patterns, architectural patterns and user interface design patterns. We'll chase a rabbit and look at where patterns fail or might not be used correctly. You'll leave this session able to identify patterns and successfully use them in all facets of your design and construction of software applications.

Citation preview

Page 1: I Love Patterns

I <3 Patterns

Matt Ruma (@mattruma)Ann Arbor Day of .NET, October 29, 2011

Page 2: I Love Patterns

You work small miracles every day.

Hunt, Andrew; Thomas, David (1999-10-20). The Pragmatic Programmer: From Journeyman to Master.

Page 3: I Love Patterns

It’s a difficult job.

Hunt, Andrew; Thomas, David (1999-10-20). The Pragmatic Programmer: From Journeyman to Master.

Page 4: I Love Patterns

There are no easy answers.

Hunt, Andrew; Thomas, David (1999-10-20). The Pragmatic Programmer: From Journeyman to Master.

Page 5: I Love Patterns

You get the job done, and do it well.

Hunt, Andrew; Thomas, David (1999-10-20). The Pragmatic Programmer: From Journeyman to Master.

Page 6: I Love Patterns

You want to become a better software developer.

Hunt, Andrew; Thomas, David (1999-10-20). The Pragmatic Programmer: From Journeyman to Master.

Page 7: I Love Patterns

Patterns will help you become a better software

developer.

Page 8: I Love Patterns

Agenda

• Patterns in the wild• Speaking in patterns• Patterns defined• Advantages of patterns• Disadvantages of patterns (not really)• Pattern examples• Chase a rabbit, look at anti-patterns• Getting started with patterns• Wrap things up

Page 9: I Love Patterns

PATTERNS IN THE WILD

Page 10: I Love Patterns

Patterns are models deserving of imitation.

Page 11: I Love Patterns

Patterns in books and movies.

Page 12: I Love Patterns

Patterns in music.

Page 13: I Love Patterns

Patterns in presentations.

Page 14: I Love Patterns

Patterns for raising children.

Page 15: I Love Patterns

On and on we could go.

• Patterns for operating a gas station.• Patterns for operating a restaurant.• Patterns for operating a customer

service desk.• Patterns for putting on a conference.• Patterns for the construction of

buildings.

Page 16: I Love Patterns

Patterns are part of everyday life.

Page 17: I Love Patterns

SPEAKING IN PATTERNS

Page 18: I Love Patterns

Is beauty in the eye of the beholder?

Alexander, Christopher (1977). A Pattern Language: Towns, Buildings, Construction.

Page 19: I Love Patterns

Each pattern describes a problem which occurs over and over again in our environment and then describes the core of the solution to that problem, in such a way that you can use this solution a million times

over, without ever doing it the same way twice.

Alexander, Christopher (1977). A Pattern Language: Towns, Buildings, Construction.

Page 20: I Love Patterns

Architecture Patterns

• Accessible Green• Four Story Limit• Warm Colors

Alexander, Christopher (1977). A Pattern Language: Towns, Buildings, Construction.

Page 21: I Love Patterns

What does all this architectural babble have to

do with software developers?

Page 22: I Love Patterns

PATTERNS DEFINED

Page 23: I Love Patterns

Patterns describe a recurring problem and a

solution.

Page 24: I Love Patterns

Each pattern, in its simplest form, is a three-part rule,

which expresses a relation between a certain context, a problem, and a solution.

Page 25: I Love Patterns

Pattern Elements

• Context is the situation in which the pattern applies.

• Problem refers to the goal you are trying to achieve in this context.

• Solution is what you’re after: a general design that anyone can apply which resolves the goal and set of constraints.

Page 26: I Love Patterns

Chocolate Chip Ratio

• Context. You are baking chocolate chip cookies in small batches for family and friends

• Problem. Determine the optimum ratio of chocolate chips to cookie dough

• Solution. Observe that most people consider chocolate to be the best part of the chocolate chip cookie. Also observe that too much chocolate may prevent the cookie from holding together, decreasing its appeal. Since you are cooking in small batches, cost is not a consideration. Therefore, use the maximum amount of chocolate chips that results in a really sturdy cookie.

Page 27: I Love Patterns

Patterns != Principles

Page 28: I Love Patterns

Patterns are discovered not created.

Alexander, Christopher (1977). Timeless Way of Building

Page 29: I Love Patterns

ADVANTAGES

Page 30: I Love Patterns

Someone has already solved your problem.

Freeman, Elisabeth; Freeman, Eric; Bates, Bert; Sierra, Kathy (2004). Head First Design Patterns

Page 31: I Love Patterns

Keeps you sane.

Page 32: I Love Patterns

Allows for change.

Page 33: I Love Patterns

Establish common terminology to improve communication within

teams.

Shalloway, Allen; Trott, James (2005). Designs Patterns Explained: A New Perspective on Object-Oriented Design

Page 34: I Love Patterns

So many words

Carpenter 1: How do you think we should build these drawers?

Carpenter 2: Well, I think we should make the joint by cutting straight down into the wood, and then cut back up the other way 45 degrees, and then going straight back down, and then …

Shalloway, Allen; Trott, James (2005). Designs Patterns Explained: A New Perspective on Object-Oriented Design

Page 35: I Love Patterns

Just right

Carpenter 1: Show we use a dovetail joint or a miter joint?

Shalloway, Allen; Trott, James (2005). Designs Patterns Explained: A New Perspective on Object-Oriented Design

Page 36: I Love Patterns

You are saying more with less.

Shalloway, Allen; Trott, James (2005). Designs Patterns Explained: A New Perspective on Object-Oriented Design

Page 37: I Love Patterns

Allows you to stay in the “design” frame of mind.

Shalloway, Allen; Trott, James (2005). Designs Patterns Explained: A New Perspective on Object-Oriented Design

Page 38: I Love Patterns

Move more quickly, less room for misunderstanding.

Shalloway, Allen; Trott, James (2005). Designs Patterns Explained: A New Perspective on Object-Oriented Design

Page 39: I Love Patterns

Motivates junior developers.

Shalloway, Allen; Trott, James (2005). Designs Patterns Explained: A New Perspective on Object-Oriented Design

Page 40: I Love Patterns

Uncle Bob says so.

Page 41: I Love Patterns

DISADVANTAGES

Page 42: I Love Patterns

Disadvantages, some so-so

• Maslow’s hammer• Too complex• Different interpretations• Whoops! Using the wrong one• Pattern happy

Shalloway, Allen; Trott, James (2005). Designs Patterns Explained: A New Perspective on Object-Oriented Design

Page 43: I Love Patterns

EXAMPLES

Page 44: I Love Patterns

Pattern Categories

• Design Patterns• Application Architecture Patterns• Database Patterns• Refactoring Patterns• Application Presentation Patterns• User Interface Patterns

Page 45: I Love Patterns

Design Patterns

• Descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context

• Purpose can be creational, structural and behavioral

• Scope can be class or object• Catalogued 23 popular patterns• Singleton, Decorator, Adapter, Façade,

Composite and FactoryGamma, Erich; Helm, Richard; Johnson, Ralph; Vlissides, John M. (1994). Design Patterns: Elements of Reusable Object-Oriented Software

Page 46: I Love Patterns

Application Architecture Patterns

• Client/Server• Layered• Multi-Tier (N-Tier)• Service Oriented Architecture (SOA)• Message Bus

Page 47: I Love Patterns

Database Patterns

• Table design– Small master– Large master

• Database normalization– First normal form– Second normal form– Third normal form or Business normal

form

Page 48: I Love Patterns

Refactoring Patterns

• Code– Extract method– Extract interface– Rename method– Replace inheritance with delegation

• Database– Drop column– Introduce soft delete– Split table– Add lookup table

Page 49: I Love Patterns

Application Presentation Patterns

• Model View Presenter (MVP)• Model View Controller (MVC)• Model View View Model (MVVM)

Page 50: I Love Patterns

User Interface Patterns

• Lazy registration• Progressive Disclosure• Forgiving format• Clear primary actions

http://uxdesign.smashingmagazine.com/2009/06/23/10-ui-design-patterns-you-should-be-paying-attention-to/

Page 51: I Love Patterns

ANTI-PATTERNSChasing a Fat Rabbit

Page 52: I Love Patterns

Anti-pattern

• Tells you why a bad solution is attractive.

• Tells you why that solution in the long term is bad.

• Suggests other patterns which may provide good solutions.

• Code smells.

Page 53: I Love Patterns

Examples of Anti-patterns

• Death march• Gold plating• God object• Object orgy• Reinventing the wheel

Page 54: I Love Patterns

GETTING STARTED WITH PATTERNS

Page 55: I Love Patterns

Start learning

Page 56: I Love Patterns

Start talking in patterns

Page 57: I Love Patterns

Start using patterns

Page 58: I Love Patterns

The best designs will use multiple design patterns

Page 59: I Love Patterns

Build you own patterns catalog

• Pattern name• Description of the problem• Solution to the problem (include

examples)• Consequences

Page 60: I Love Patterns

CONCLUSION

Page 61: I Love Patterns

Wrapping things up

• Patterns are everywhere.• Patterns describe a problem and provide a

solution.• Patterns embody principles.• The advantages of using patterns far out weigh

their disadvantages.• Beware of anti-patterns.• Just do it• Using patterns in all facets of software

development will make us better developers.• Better developers write better software.

Page 62: I Love Patterns

62

References• The Timeless Way of Building by Christopher Alexander

• A Pattern Language: Towns, Buildings, Construction by Christopher Alexander, Sara Ishikawa and Murray Silverstein

• Design Patterns: Elements of Reusable Object-Oriented Software by Eric Gamma, Richard Helm, Ralph Johnson and John Vlissides

• Design Patterns Explained: A New Perspective on Object-Oriented Design by Alan Shalloway and James Trott

• Refactoring to Patterns by Joshua Kerievsky

• The Pragmatic Programmer: From Journeyman to Master by Andrew Hunt and David Thomas

• Agile Principles, Patterns and Practices in C# by Robert Martin and Micah Martin

• Head First Design Patterns by Eric Freeman, Elisabeth Freeman, Kathy Sierra and Bert Bates

• Universal Principles of Design by William Lidwell, Kritina Holden and Jill Butler

• Refactoring Databases: Evolutionary Database Design Scott Ambler and Pramodkumar Sadalage

• Adrenaline Junkies and Template Zombies: Understanding Patterns of Project Behavior by Tom Demarco, Peter Hruschka, Tim Lister and Suzanne Robertson

• Smashing Magazine http://smashingmagazine.com

Page 63: I Love Patterns

Go work some small miracles.

Matt RumaMaster Technology GuideEpitec Group

mattruma

mattruma.com

[email protected]