Vous êtes sur la page 1sur 3

Articles|News|Weblogs|Buzz|Books|Forums

LeadingEdgeJava|Discuss|Print|Email|FirstPage|Previous|Next
SponsoredLink

LeadingEdgeJava

HowtoUseDesignPatterns
AConversationwithErichGamma,PartI
byBillVenners
May23,2005

Page1of3>>
Summary
ADVERTISEMENT
Amongdevelopers,designpatternsareapopularwaytothinkabout
design,butwhatistheproperwaytothinkaboutdesignpatterns?Inthis
interview,ErichGamma,coauthorofthelandmarkbook,DesignPatterns,
talkswithBillVennersabouttherightwaytothinkaboutandusedesign
patterns.
ErichGammaleptontothesoftwareworldstagein1995ascoauthorofthebestselling
bookDesignPatterns:ElementsofReusableObjectOrientedSoftware(AddisonWesley,
1995)[seeResources].Thislandmarkwork,oftenreferredtoastheGangofFour(GoF)
book,cataloged23specificsolutionstocommondesignproblems.In1998,heteamed
upwithKentBecktoproduceJUnit[seeResources],thedefactounittestingtoolinthe
Javacommunity.GammacurrentlyisanIBMDistinguishedEngineeratIBM'sObject
TechnologyInternational(OTI)labinZurich,Switzerland.Heprovidesleadershipinthe
Eclipsecommunity,andisresponsiblefortheJavadevelopmenteffortfortheEclipse
platform[seeResources].
OnOctober27,2004,BillVennersmetwithErichGammaattheOOPSLAconferencein
Vancouver,Canada.Inthisinterview,whichwillbepublishedinmultipleinstallmentsin
LeadingEdgeJavaonArtimaDeveloper,Gammagivesinsightsintosoftwaredesign.In
thisfirstinstallment,Gammadescribesgiveshisopinionontheappropriatewaystothink
aboutandusedesignpatterns,anddescribesthedifferencebetweenpatternslibraries,
suchasGoF,andanAlexandrianpatternlanguage.

Therealvalueofdesignpatterns
BillVenners:BruceEckelandIteachdesignclasses,andwe'vefoundthatpeoplereally
wanttoknowtheGangofFour(GoF)patterns.Patternshelpsellseminars.There'salot
ofmarketinghypearounddesignpatterns.
ErichGamma:Still,after10years?
BillVenners:Yes.Peoplewanttoknowpatterns,andIsuspectagreatdealofthatis
because"patterns"isstillabuzzword.I'dliketocutthroughthehypeandfindoutwhat
youthinkpeopleshouldactuallydowithpatterns.Whatshouldtheirattitudebeabout
patterns?Howcanpeopleusepatternstodoabetterjob?Whatistherealvalue?

ErichGamma:Ithinkpatternsasawholecanhelppeoplelearnobjectorientedthinking:
howyoucanleveragepolymorphism,designforcomposition,delegation,balance
responsibilities,andprovidepluggablebehavior.Patternsgobeyondapplyingobjectsto
somegraphicalshapeexample,withashapeclasshierarchyandsomepolymorphic
drawmethod.Youreallylearnaboutpolymorphismwhenyou'veunderstoodthepatterns.
SopatternsaregoodforlearningOOanddesigningeneral.
Thenontopofthat,eachindividualpatternhasadifferentcharacteristictohelpyouin
someplacewhereyouneedmoreflexibilityorneedtoencapsulateanabstraction,or
needtomakeyourcodelesscoupled.Thisisareallybigissueinalargesystem.Howdo
youpreserveyourlayers?Howdoyouavoidupcallsorcirculardependencies?TheGoF
patternsprovideyouwithlittletoolsthathelpyouwiththeseproblems.Theydosonotby
givingapatsolutionbutbyexplainingtradeoffs.Eventhoughpatternsareabstracted
fromconcreteuses,theyalsoprovideyouvaluableimplementationhints.Frommy
perspectiveitisthefactthatpatternsareimplementablethatmakesthemsovaluable.
Patternsaredistilledfromtheexperiencesofexperts.Theyenableyoutorepeata
successfuldesigndonebysomeoneelse.Bydoingsoyoucanstandontheshouldersof
theexpertsanddonothavetoreinventthewheel.However,sincepatternsenablemany
implementationvariationsyoustillhavetokeepthebrainturnedon.Finally,since
patternsprovideyouwithnamesfordesignbuildingblockstheyprovideyouwitha
vocabularytodescribeanddiscussaparticulardesign.
Theotherquestionwashowweshouldteachpatterns.NotthatIknowexactlywhatyou
shoulddo,butIthinkwhatyoushouldnotdoishaveaclassandjustenumeratethe23
patterns.Thisapproachjustdoesn'tbringanything.Youhavetofeelthepainofadesign
whichhassomeproblem.Iguessyouonlyappreciateapatternonceyouhavefeltthis
designpain.
BillVenners:Whatpain?
ErichGamma:Likerealizingyourdesignisn'tflexibleenough,asinglechangeripples
throughtheentiresystem,youhavetoduplicatecode,orthecodeisjustgettingmore
andcomplex.Ifyouthenapplyapatterninsuchamessysituationitcanhappenthatthe
paingoesawayandyoufeelgoodafterwards.It'saneyeopenertorealizethatoh,
actuallythispattern,factoryorstrategy,isasolutiontomyproblem.AndIthinkthat'sthe
reallyinterestingwaytoteach.
WhenIstartedteachingitwasreallyboring,becauseIwasjustenumeratingthepatterns.
Ifounditfarmoreinterestingtotrytomotivatewithrealexampleshowtoapplypatterns.
Inotherwords,youreallyneedtopresenttheprobleminarealisticcontextsynthetic
examplesdonotfly.AtOOPSLAIreceivedaHeadsFirstDesignPatternsbook[see
Resources].It'sagreatbook,notonlybecauseitisfuntoreadbutalsobecausetheyare
abletocommunicatetheessenceofdesignpatternsinanovelandhighlyvisualway.
BillVenners:Isthevalueofpatterns,then,thatintherealworldwhenIfeelaparticular
kindofpainI'llbeabletoreachforaknownsolution?
ErichGamma:ThisisdefinitelythewayI'drecommendthatpeopleusepatterns.Donot
startimmediatelythrowingpatternsintoadesign,butusethemasyougoand
understandmoreoftheproblem.BecauseofthisIreallyliketousepatternsafterthe
fact,refactoringtopatterns.OnecommentIsawinanewsgroupjustafterpatterns
startedtobecomemorepopularwassomeoneclaimingthatinaparticularprogramthey
triedtouseall23GoFpatterns.Theysaidtheyhadfailed,becausetheywereonlyable
touse20.Theyhopedtheclientwouldcallthemagaintocomebackagainsomaybe
theycouldsqueezeintheother3.
Tryingtouseallthepatternsisabadthing,becauseyouwillendupwithsynthetic
designsspeculativedesignsthathaveflexibilitythatnooneneeds.Thesedays
softwareistoocomplex.Wecan'taffordtospeculatewhatelseitshoulddo.Weneedto

reallyfocusonwhatitneeds.That'swhyIlikerefactoringtopatterns.Peopleshould
learnthatwhentheyhaveaparticularkindofproblemorcodesmell,aspeoplecallit
thesedays,theycangototheirpatternstoolboxtofindasolution.
BillVenners:That'sfunny,becausemysecondquestionwasthatIhaveobservedthat
oftenpeoplefeelthedesignwiththemostpatternsisthebest.Inourdesignseminar,I
havetheparticipantsdoadesignproject,whichtheypresenttotheothersattheendof
theseminar.Almostinvariably,thepresenterswanttoshowoffhowmanypatternsthey
usedintheirdesign,eventhoughItrytotellthemthegoalisaclean,easytounderstand
API,nottowinanIusedthemostpatternscontest.Ijustheardyousaythesamething,
thatthat'snottherightwaytothinkaboutpatterns.Ifnot,whatistheproperjustification
forusingpatternsindesigns?
ErichGamma:Alotofthepatternsareaboutextensibilityandreusability.Whenyou
reallyneedextensibility,thenpatternsprovideyouwithawaytoachieveitandthisis
cool.Butwhenyoudon'tneedit,youshouldkeepyourdesignsimpleandnotadd
unnecessarylevelsofindirection.OneofourEclipsemottosisthatwewantextensibility
whereitmatters.Actually,ifyouareinterestedinhowweusepatternsinEclipseIdidan
attempttocapturetheirusesinachapterintheContributingtoEclipsebook[see
Resources].InthischapterIuseddesignpatternstoexplainpiecesoftheEclipse
architecture.
BillVenners:Byextensibility,whatdoyoumean?
ErichGamma:Thatyoucancustomizebehaviorwithouthavingtotouchexistingcode
oneoftheclassicalOOthemes.Youcanreusesomethingadaptedtoyourparticular
problem.
Page1of3>>

LeadingEdgeJava|Discuss|Print|Email|FirstPage|Previous|Next

SponsoredLinks

HowtoApply

Adsby Google

DesignPatterns

HowtoPrograminJava

Search

Web

Artima.com

Copyright19962017Artima,Inc.AllRightsReserved.PrivacyPolicyTermsofUseAdvertisewithUs

Vous aimerez peut-être aussi