Scott Cate (@ScottCate) CloudDB.com Session Code: DPR401

Preview:

Citation preview

Patterns for the Rest of UsScott Cate (@ScottCate)CloudDB.comSession Code: DPR401

Design Patterns for the Rest of Us! DPR401Patterns 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 PatternsTarget audience for this talk

You know the language very wellYou are an advanced programmerBUT …..

It’s difficult to explain what your code doesOthers tell you your code is hard to readYour code is buggy / hard to maintainChanging something little causes other unknownsYOU ARE NOT ALONE!IT IS HARD TO ADMIT THIS!

The Life Cycle of Bad Source CodeRewrite == expensive

The original author is goneThe code is hard to readHard to understand functionalityCause to rewrite / replaceBetter code with patternsProprietary == EXPENSIVE!

Where We Started! (Most of us)

OO Spaghetti CodeNot my code, my code is good to me

Is that because you wrote it?It’s in your head so you understand itIs the code hard to read / explain?

Easy to get started with sloppy code but…It’s hard to add functionality laterIt’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 monsterProven Logical TechniquesTech communities agree on patterns

(it’s hard to get people to agree)Common Vocabulary

Easy to understand / inherit / readJust a term – not a golden solution

GOF: 3 Design Pattern CategoriesDozens of more categories, these are GOF

CreationHow, Where, When, Why do you instantiate objects?GOF: Factories, Builder, Prototype, Singleton

StructuralChange, Migrate, Add to, Copy, Split, Move objectsGOF: Adapter, Bridge, Composite, Decorator, Façade, Flyweight, Proxy

BehavioralPassing around, working on, alter, add functionality to objectsCommand, Chain of Responsibility, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template, Visitor

Commonly Used Design Patterns!Observer Pattern – Start nice and easy

demo / write code

Commonly used Design Patterns!Singleton Pattern – Very common / Easy to write

demo / write code

Commonly Used Design Patterns!Factory Pattern – Delegate “New”ing objects

demo / write code

Commonly Used Design Patterns!Command (AKA Action) Pattern – Store, Queue, Execute

demo / write code

Commonly Used Design Patterns!Template – Delegate base functionality

demo / write code

Commonly Used Design Patterns!State Pattern – Delegate action based on state

demo / write code

Commonly Used Design Patterns!Strategy Pattern – Algorithms / Single or Multi Pass

demo / write code

Anti PatternsSquare Pegs / Round Holes

Don’t use a pattern just becauseDon’t over engineerDon’t make fun of othersDon’t overuse a pattern

If every class uses the same patternit’s probably over used.This is an easy trap to fall into.

Special ThanksBrainstorm + session guidance

Jeffrey PalermoGlenn BlockWard BellJames AveryPaul GlavichJeff Widmer

Recommended Reading(where to learn more)

Elements of Reusable Object-Oriented SoftwareCommonly known as “The Gang of Four”

Martin Fowler’s PoEAAPatterns of Enterprise Application Architecture

O’Reilly: Head First Design PatternsJoshua Kerievsky

Refactoring to PatternsDoFactory.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 tickethttp://www.microsoft.com/visualstudio http://www.microsoft.com/visualstudio/en-us/products/teamsystem/default.mspxPlease visit us in the TLC blue area

www.microsoft.com/teched

Sessions On-Demand & Community

http://microsoft.com/technet

Resources for IT Professionals

http://microsoft.com/msdn

Resources for Developers

www.microsoft.com/learningMicrosoft Certification and Training Resources

www.microsoft.com/learning

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.

Recommended