27

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

Embed Size (px)

Citation preview

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

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

Page 3: Scott Cate (@ScottCate) CloudDB.com Session 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.

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

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!

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

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!

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

Where We Started! (Most of us)

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

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

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

How We’ve Cleaned Up Our Code (Most of us)

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

Developing by Contract The unknown neighbor

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

Handling Change Requests Should be this easy

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

Building Blocks

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

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

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

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

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

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

demo / write code

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

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

demo / write code

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

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

demo / write code

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

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

demo / write code

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

Commonly Used Design Patterns!Template – Delegate base functionality

demo / write code

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

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

demo / write code

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

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

demo / write code

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

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.

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

Special ThanksBrainstorm + session guidance

Jeffrey PalermoGlenn BlockWard BellJames AveryPaul GlavichJeff Widmer

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

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

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

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

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

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

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

Complete an evaluation on CommNet and enter to win!

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

© 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.