Scott Cate CloudDB.com Session Code: DPR401
Design Patterns for the Rest of Us! DPR401 Patterns Patterns Patterns. You hear about them everywhere. We're told to use them and call them by names, as if the pattern is a colleague of ours. Hey, did you see the {Fill In Blank} Pattern in the demo this morning? If you feel left out in conversations where Pattern buzzwords are thrown around, this session is for you. This session introduces Patterns with imagery, code, terms, and fun and games to help you better understand and remember pattern usage.
Design Patterns Target audience for this talk You know the language very well You are an advanced programmer BUT ….. It’s difficult to explain what your code does Others tell you your code is hard to read Your code is buggy / hard to maintain Changing something little causes other unknowns YOU ARE NOT ALONE! IT IS HARD TO ADMIT THIS!
The Life Cycle of Bad Source Code Rewrite == expensive The original author is gone The code is hard to read Hard to understand functionality Cause to rewrite / replace Better code with patterns Proprietary == EXPENSIVE!
Where We Started! (Most of us)
OO Spaghetti Code Not my code, my code is good to me Is that because you wrote it? It’s in your head so you understand it Is the code hard to read / explain? Easy to get started with sloppy code but… It’s hard to add functionality later It’s hard to make core changes later
How We’ve Cleaned Up Our Code (Most of us)
Developing by Contract The unknown neighbor
Handling Change Requests Should be this easy
Building Blocks
What is a Design Pattern? (This is a legit question) No, it’s not a scary monster Proven Logical Techniques Tech communities agree on patterns (it’s hard to get people to agree) Common Vocabulary Easy to understand / inherit / read Just a term – not a golden solution
GOF: 3 Design Pattern Categories Dozens of more categories, these are GOF Creation How, Where, When, Why do you instantiate objects? GOF: Factories, Builder, Prototype, Singleton Structural Change, Migrate, Add to, Copy, Split, Move objects GOF: Adapter, Bridge, Composite, Decorator, Façade, Flyweight, Proxy Behavioral Passing around, working on, alter, add functionality to objects Command, Chain of Responsibility, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template, Visitor
Commonly Used Design Patterns! Observer Pattern – Start nice and easy
Commonly used Design Patterns! Singleton Pattern – Very common / Easy to write
Commonly Used Design Patterns! Factory Pattern – Delegate “New”ing objects
Commonly Used Design Patterns! Command (AKA Action) Pattern – Store, Queue, Execute
Commonly Used Design Patterns! Template – Delegate base functionality
Commonly Used Design Patterns! State Pattern – Delegate action based on state
Commonly Used Design Patterns! Strategy Pattern – Algorithms / Single or Multi Pass
Anti Patterns Square Pegs / Round Holes Don’t use a pattern just because Don’t over engineer Don’t make fun of others Don’t overuse a pattern If every class uses the same pattern it’s probably over used. This is an easy trap to fall into.
Special Thanks Brainstorm + session guidance Jeffrey Palermo Glenn Block Ward Bell James Avery Paul Glavich Jeff Widmer
Recommended Reading (where to learn more) Elements of Reusable Object-Oriented Software Commonly known as “The Gang of Four” Martin Fowler’s PoEAA Patterns of Enterprise Application Architecture O’Reilly: Head First Design Patterns Joshua Kerievsky Refactoring to Patterns DoFactory.com
Track Resources Visit the DPR TLC for a chance to win a copy of Visual Studio Team Suite. Daily drawing occurs every day in the TLC at 4:15pm. Stop by for a raffle ticket us/products/teamsystem/default.mspx Please visit us in the TLC blue area
Sessions On-Demand & Community Resources for IT Professionals Resources for Developers Microsoft Certification and Training Resources Microsoft Certification & Training Resources Resources
Complete an evaluation on CommNet and enter to win!
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.