Upload
matt-ruma
View
113
Download
5
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
I <3 Patterns
Matt Ruma (@mattruma)Ann Arbor Day of .NET, October 29, 2011
You work small miracles every day.
Hunt, Andrew; Thomas, David (1999-10-20). The Pragmatic Programmer: From Journeyman to Master.
It’s a difficult job.
Hunt, Andrew; Thomas, David (1999-10-20). The Pragmatic Programmer: From Journeyman to Master.
There are no easy answers.
Hunt, Andrew; Thomas, David (1999-10-20). The Pragmatic Programmer: From Journeyman to Master.
You get the job done, and do it well.
Hunt, Andrew; Thomas, David (1999-10-20). The Pragmatic Programmer: From Journeyman to Master.
You want to become a better software developer.
Hunt, Andrew; Thomas, David (1999-10-20). The Pragmatic Programmer: From Journeyman to Master.
Patterns will help you become a better software
developer.
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
PATTERNS IN THE WILD
Patterns are models deserving of imitation.
Patterns in books and movies.
Patterns in music.
Patterns in presentations.
Patterns for raising children.
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.
Patterns are part of everyday life.
SPEAKING IN PATTERNS
Is beauty in the eye of the beholder?
Alexander, Christopher (1977). A Pattern Language: Towns, Buildings, Construction.
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.
Architecture Patterns
• Accessible Green• Four Story Limit• Warm Colors
Alexander, Christopher (1977). A Pattern Language: Towns, Buildings, Construction.
What does all this architectural babble have to
do with software developers?
PATTERNS DEFINED
Patterns describe a recurring problem and a
solution.
Each pattern, in its simplest form, is a three-part rule,
which expresses a relation between a certain context, a problem, and a solution.
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.
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.
Patterns != Principles
Patterns are discovered not created.
Alexander, Christopher (1977). Timeless Way of Building
ADVANTAGES
Someone has already solved your problem.
Freeman, Elisabeth; Freeman, Eric; Bates, Bert; Sierra, Kathy (2004). Head First Design Patterns
Keeps you sane.
Allows for change.
Establish common terminology to improve communication within
teams.
Shalloway, Allen; Trott, James (2005). Designs Patterns Explained: A New Perspective on Object-Oriented Design
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
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
You are saying more with less.
Shalloway, Allen; Trott, James (2005). Designs Patterns Explained: A New Perspective on Object-Oriented Design
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
Move more quickly, less room for misunderstanding.
Shalloway, Allen; Trott, James (2005). Designs Patterns Explained: A New Perspective on Object-Oriented Design
Motivates junior developers.
Shalloway, Allen; Trott, James (2005). Designs Patterns Explained: A New Perspective on Object-Oriented Design
Uncle Bob says so.
DISADVANTAGES
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
EXAMPLES
Pattern Categories
• Design Patterns• Application Architecture Patterns• Database Patterns• Refactoring Patterns• Application Presentation Patterns• User Interface 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
Application Architecture Patterns
• Client/Server• Layered• Multi-Tier (N-Tier)• Service Oriented Architecture (SOA)• Message Bus
Database Patterns
• Table design– Small master– Large master
• Database normalization– First normal form– Second normal form– Third normal form or Business normal
form
Refactoring Patterns
• Code– Extract method– Extract interface– Rename method– Replace inheritance with delegation
• Database– Drop column– Introduce soft delete– Split table– Add lookup table
Application Presentation Patterns
• Model View Presenter (MVP)• Model View Controller (MVC)• Model View View Model (MVVM)
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/
ANTI-PATTERNSChasing a Fat Rabbit
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.
Examples of Anti-patterns
• Death march• Gold plating• God object• Object orgy• Reinventing the wheel
GETTING STARTED WITH PATTERNS
Start learning
Start talking in patterns
Start using patterns
The best designs will use multiple design patterns
Build you own patterns catalog
• Pattern name• Description of the problem• Solution to the problem (include
examples)• Consequences
CONCLUSION
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.
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
Go work some small miracles.
Matt RumaMaster Technology GuideEpitec Group
mattruma
mattruma.com