seven habits of effective pattern writers facade pattern

22
Seven Habits of Effective Seven Habits of Effective Pattern Writers Pattern Writers Facade Pattern Facade Pattern PH pp. 145-152 PH pp. 145-152 GoF pp. 185-193 GoF pp. 185-193 John Klacsmann John Klacsmann

Upload: uzuri

Post on 11-Feb-2016

51 views

Category:

Documents


0 download

DESCRIPTION

Seven Habits of Effective Pattern Writers Facade Pattern. PH pp. 145-152 GoF pp. 185-193 John Klacsmann. Other Famous Gang of Four’s. Chinese Communist Politicians (1976) British Post-Punk Band (1977-1984). Seven Habits of Effective Pattern Writers. 1. Take Time to Reflect - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Seven Habits of Effective Pattern Writers Facade Pattern

Seven Habits of Effective Pattern WritersSeven Habits of Effective Pattern WritersFacade PatternFacade PatternPH pp. 145-152PH pp. 145-152

GoF pp. 185-193GoF pp. 185-193

John KlacsmannJohn Klacsmann

Page 2: Seven Habits of Effective Pattern Writers Facade Pattern

Other Famous Other Famous Gang of Four’sGang of Four’s

Chinese Communist Politicians (1976)Chinese Communist Politicians (1976)

British Post-Punk Band (1977-1984)British Post-Punk Band (1977-1984)

Page 3: Seven Habits of Effective Pattern Writers Facade Pattern

Seven Habits of Effective Pattern WritersSeven Habits of Effective Pattern Writers

1.1. Take Time to Reflect Take Time to Reflect2.2. Adhere to a Structure Adhere to a Structure3.3. Be Concrete Early and Often Be Concrete Early and Often4.4. Keep Patterns Distinct and Complementary Keep Patterns Distinct and Complementary5.5. Present Effectively Present Effectively6.6. Iterate Tirelessly Iterate Tirelessly7.7. Collect and Incorporate Feedback Collect and Incorporate Feedback

Page 4: Seven Habits of Effective Pattern Writers Facade Pattern

1.1. Take Time To Reflect Take Time To Reflect

Think about past problems and solutionsThink about past problems and solutionsRecord Your ExperiencesRecord Your Experiences Describe the problemDescribe the problem Why is it difficult?Why is it difficult? Write down new approachesWrite down new approaches Why did it fail? Why did it succeed?Why did it fail? Why did it succeed? Forms raw material of patternsForms raw material of patterns

Page 5: Seven Habits of Effective Pattern Writers Facade Pattern

1. Take Time To Reflect1. Take Time To Reflect

Identify Patterns You Already KnowIdentify Patterns You Already KnowIf find something new & unique make sure If find something new & unique make sure you have at least you have at least twotwo existing examples of existing examples of a problem & solutiona problem & solution

Page 6: Seven Habits of Effective Pattern Writers Facade Pattern

2. Adhere to a Structure2. Adhere to a Structure

Pattern: “Pattern: “A Structured ExpositionA Structured Exposition of a of a solution to a problem in context”solution to a problem in context”Include:Include: NameName Statement of ProblemStatement of Problem Context and Justification of SolutionContext and Justification of Solution Solution itselfSolution itself

Settle on structure & keep it consistentSettle on structure & keep it consistent

Page 7: Seven Habits of Effective Pattern Writers Facade Pattern

3. Be Concrete Early and Often3. Be Concrete Early and Often

People understand better when presented People understand better when presented in concrete first then abstractin concrete first then abstractUse examples and counterexamplesUse examples and counterexamples““Tell the whole truth”Tell the whole truth” Warn reader of potential pitfallsWarn reader of potential pitfalls Extra CostExtra Cost Ill-behavior under certain circumstancesIll-behavior under certain circumstances Other patternsOther patterns Etc.Etc.

Page 8: Seven Habits of Effective Pattern Writers Facade Pattern

4. Keep patterns distinct and 4. Keep patterns distinct and complementarycomplementary

Insure patterns are distinct Insure patterns are distinct Might not be obviousMight not be obviousAsk: “How is pattern X different from Ask: “How is pattern X different from pattern Y?”pattern Y?”Let intents of patterns be guide to Let intents of patterns be guide to differences, not class structuresdifferences, not class structuresSpend time comparing and contrasting Spend time comparing and contrasting your patternsyour patterns

Page 9: Seven Habits of Effective Pattern Writers Facade Pattern

5. Present Effectively5. Present Effectively

Typesetting and Writing Style are Typesetting and Writing Style are importantimportantUse drawings liberally to illustrate key Use drawings liberally to illustrate key pointspointsMake pattern approachableMake pattern approachable Use down-to-earth writing styleUse down-to-earth writing style Write conversationallyWrite conversationally

Page 10: Seven Habits of Effective Pattern Writers Facade Pattern

6. Iterate Tirelessly6. Iterate Tirelessly

Pattern writing is an ongoing processPattern writing is an ongoing processExpect to write and rewrite your pattern Expect to write and rewrite your pattern many timesmany timesDon’t perfect before moving onDon’t perfect before moving on

Page 11: Seven Habits of Effective Pattern Writers Facade Pattern

7. Collect and Incorporate 7. Collect and Incorporate FeedbackFeedback

““No pattern can be trusted until it is used No pattern can be trusted until it is used by by someone other than its authorsomeone other than its author””Make pattern understandable to people Make pattern understandable to people who have never had the problemwho have never had the problemDiscuss with colleaguesDiscuss with colleaguesLook for opportunities to useLook for opportunities to useGet comments & be prepared to hear the Get comments & be prepared to hear the worstworst Give reviewers benefit of doubtGive reviewers benefit of doubt Bend over backwards to make them happyBend over backwards to make them happy

Page 12: Seven Habits of Effective Pattern Writers Facade Pattern

Seven Habits of Effective Pattern WritersSeven Habits of Effective Pattern Writers

Follow these steps to make your own Follow these steps to make your own patterns betterpatterns betterThe better your patterns are, the more The better your patterns are, the more impact they’ll haveimpact they’ll have

Page 13: Seven Habits of Effective Pattern Writers Facade Pattern

GoF’s Facade PatternGoF’s Facade Pattern

Make it simplerMake it simplerDefines a higher-level interface that makes Defines a higher-level interface that makes the subsystem easier to usethe subsystem easier to use

From: http://www.csc.calpoly.edu/~dbutler/tutorials/winter96/patterns/tutorial.html

Page 14: Seven Habits of Effective Pattern Writers Facade Pattern

MotivationMotivation

Structuring into subsystems helps reduce Structuring into subsystems helps reduce complexitycomplexityProvides a single, simplified interface to Provides a single, simplified interface to the more general (complex) facilities of a the more general (complex) facilities of a subsytemsubsytem

Page 15: Seven Habits of Effective Pattern Writers Facade Pattern

Compiler ExampleCompiler Example

Contains subsystem of classes Contains subsystem of classes Most clients don’t care about details – just Most clients don’t care about details – just want to compilewant to compileLow-level only complicates taskLow-level only complicates task

Page 16: Seven Habits of Effective Pattern Writers Facade Pattern

Compiler ExampleCompiler Example

Compiler class acts as FaçadeCompiler class acts as FaçadeProvides higher level interface that shields clients from Provides higher level interface that shields clients from lower-level classeslower-level classesMakes life easier for programmer without hiding the low-Makes life easier for programmer without hiding the low-level functionality completelylevel functionality completelyPuts all pieces of compile operation togetherPuts all pieces of compile operation together

Page 17: Seven Habits of Effective Pattern Writers Facade Pattern

When to use FacadeWhen to use Facade

When you want a simple interface to a When you want a simple interface to a complex subsystemcomplex subsystem Provides simple default view good enough for Provides simple default view good enough for

most clientsmost clients

Page 18: Seven Habits of Effective Pattern Writers Facade Pattern

When To Use FacadeWhen To Use Facade

When there are many dependencies When there are many dependencies between clients and implementation between clients and implementation classesclasses Decouples subsystem from clientsDecouples subsystem from clients

When you want to layer your subsystemsWhen you want to layer your subsystems Simplify dependencies between subsystems Simplify dependencies between subsystems

by making them communicate only through by making them communicate only through their facadestheir facades

Page 19: Seven Habits of Effective Pattern Writers Facade Pattern

StructureStructure

FaçadeFaçade Delegates client requests to appropriate Delegates client requests to appropriate

subsystem objectssubsystem objects

Subsystem ClassesSubsystem Classes Implement subsystemImplement subsystem Handle work assigned by FaçadeHandle work assigned by Façade Have no knowledge of façade (keep no Have no knowledge of façade (keep no

references)references)

Page 20: Seven Habits of Effective Pattern Writers Facade Pattern

BenefitsBenefits

Shields client from subsystemShields client from subsystem Reduces number of objects the client deals withReduces number of objects the client deals with Makes subsystem easier to useMakes subsystem easier to usePromotes weak coupling between subsystem Promotes weak coupling between subsystem and its clientsand its clients Helps eliminate complex or circular dependenciesHelps eliminate complex or circular dependencies Minimizes recompilation time needed for small Minimizes recompilation time needed for small

subsystem changesubsystem changeApplications can still use subsystem classes if Applications can still use subsystem classes if neededneeded Provides both ease of use & generalityProvides both ease of use & generality

Page 21: Seven Habits of Effective Pattern Writers Facade Pattern

How is this different then Mediator?How is this different then Mediator?

Mediator abstracts communication Mediator abstracts communication betweenbetween objects, centralizing functionality objects, centralizing functionalityMediator’s colleagues are aware of it and Mediator’s colleagues are aware of it and communicate with it instead of with each communicate with it instead of with each otherotherFaçade abstracts the interface to a Façade abstracts the interface to a subsystem to make it easiersubsystem to make it easierIt doesn’t provide any new functionality It doesn’t provide any new functionality and subsystem classes don’t know about itand subsystem classes don’t know about it

Page 22: Seven Habits of Effective Pattern Writers Facade Pattern

Questions?Questions?