Tải bản đầy đủ - 0 (trang)
Chapter 5. You Are What You Eat

Chapter 5. You Are What You Eat

Tải bản đầy đủ - 0trang

languagesassimilarasC#andJava.They'realikeinmany

waysbutwilltakeyourdesignindramaticallydifferent

directions.Somecustomersnaivelytakesmallsipsof

freedomwithtoolslikeVisualBasic.Eventually,those

departmentaltoolsgrowandescape,forcingthecustomer

togulpfromtheMicrosoftfirehose.

Bewareoftoolsthatcouple.Proprietarytoolsoftenmakeit

tooeasytomakesweepingdecisionsonthefly,without

consideringconsequences.Awholegenerationoftools,like

PowerBuilderandOracleForms,coupledapplicationstothe

databaseinunnaturalways.Onlytheapplicationand

databasevendorscameawaysmiling.Often,whenyou

makethedecisiontotightlycoupletwosubsystems,you

losethepracticalabilitytoseparatethemsoonafter.Oneof

myclientsusedatoolthatencouragedimbeddedSQLin

theirbusinesstier.Whenthetoolfelloutoffavor10years

later,theypaidaquarterofamilliondollarstorewritea

tinyfrontendbecausetheycouldn'textractthebusiness

logic.

Inthischapter,I'lldiscussdecisionsthathavefar-reaching

implications.Youarewhatyoueat,andyourapplicationis

exactlywhatyoufeedit.Ifyougiveitasteadydietofbloat,

you'llbuildbloatware.Ifyoufeeditfaddietsfullof

temperamental,experimentaltechnologies,you'llbuildfinicky,

temperamentalsystems.Ifyoufeeditthosesweetandsticky

frameworksthatgoopeverythingtogether,you'llget

applicationsstucktogetherinunnaturalways.Ifinsteadyou

feedyourcodealight,pragmaticdietoftherightpiecesinthe

rightproportions,thenyouruserswillloveyou.Your

applicationswilltakeonthepersonalityoftheframeworksthat

youuse.



5.1GoldenHammers

InmyfirstandsecondJavabooks,Iaddressedantipatterns,

patternsofsolutionsthatbreakinsystemicways.Byfarthe

mostcommonantipatternisthegoldenhammer.Asaweekend

builder,Iknowthemetaphorwell.Mostcarpentershaveatool

intheboxthat'ssobeautifulthattheywanttouseitforevery

task.I'mtheposterboy.I'veliterallyusedacircularsawwitha

carbidebladetocutwire.Javadevelopersarenodifferent.All

ofushavedevelopedfavorites.Inthissection,I'lllayouta

beautifulsetofgoldenhammersforyourinspection.Chances

aregoodthatyou'veusedonetohammertheoccasionalscrew.



5.1.1TheAllure

Anantipatternisabitterideathatseemssweetatthetime.A

goldenhammerattractsaJavaprogrammerlikeaboxofKrispy

KremesandabottleofJolt.Thepowerofbadframeworksover

otherwiseintelligentdevelopershassometimesbewilderedme,

butIguessit'sgoodforbusiness.

Sometimes,programmersdothedamagetothemselves.Past

successcancloudyourjudgment.IlearnedXMLwhileworking

onaverysuccessfulprojectandafterwards,Iwantedtouseit

everywhere,fromwritingsimple,four-lineconfigurationfilesto

buildinganalternativeprogramminglanguage.Othershavehad

thesameexperienceswithCORBA,persistenceframeworks,

webservices,andevenJavaitself.



5.1.1.1Thesalesprocess

Othertimes,aggressivemarketingorsalescandoyouin.

Understandthatthestakesarehigh,andthisindustryspends



millionsofdollarsatthedropofahattogetyoutolikeanduse

something.Ifyou'remakingamajorbuyingdecisionwiththe

helpofasalesstaff,beverycareful.Ifyoudon'tknowhowthe

processworks,youcan'tmakethemostinformeddecision.

SinceI'veworkedinsales,Icantellyouhowthatprocess

worksfromtheinside.Figure5-1showsacombinedversionof

allofthetechnicalsalesprocessesthatIhaveseenfromthe

inside.



Figure5-1.KnowingthetypicalJ2EEsales

processhelpsyoubuysmarter



Here'salittlemoredetailabouteachstep:



Prospecting

Thebestsalespeoplemakehundredsofphonecallsand

minetheircustomersforleads.Thegoalistoestablishan

interestintheirproduct.Oncethesalespersonhas

establishedinterest,she'lltrytogettothedecisionmaker.

That'scalledgettingtopower.Thefinalstepistoestablish

thatthecustomerhasthebudgettobuytheproduct.If

you'reaserousbuyer,don'tshareyouroverallbudgetwith

yourvendor!They'llusethatinformationagainstyou.



Securingsponsorship

Salesrepsknowthatsalesinvolvinganinsidesponsor



(usuallycalledapowersponsor)aremoresuccessful

becausethere'snotrustbarriertoovercome.It'softena

goodrelationshipforbothparties.Ifyou'vealreadydecided

onatechnicalsolutionandyou'retryingtosellatechnical

solutiontoyourmanagement,youcanuseyourroleasa

powersponsortogetyourvendortodoalotofyour

legworkforyou.Chancesaregoodthattheyhavemuch

moreinformation.



Gettingagreement(pre-close)

Thesalesrepcomesin,buyslunch,andslingsaroundsome

nicecoffeemugsandcoolpens.Intherelationshipstage,

thesalespersonwantstobuildupaleveloftrust.Inthe

relationshipbuildingstage,thesalesreptriestogetalistof

objections.Theirgoalistogetyoutoagreetobuythe

softwareoncetheyovercomeallofyourobjections.



Execute(technicalsales)

Armedwithasetofobjections,thevendorpassescontrolof

thesalefromthereptothetechnicalsalesteam.Thesales

teamcantakeanumberofdifferentapproaches,all

designedtoovercomeyourobjectionsandmakethesale.

Theymayincludeoneormoreoftheseelements:

Technicalpresentations.Usethesetoyouradvantage.

Letyourvendoranswercriticalquestionsabouttheir

product.Becareful,though:thevendorisnotthebest

sourceofinformationabouttheircompetition.(Infact,

whileIwasatIBM,Ifoundthatcertainvendorswere

notoriouslybad.)

Proof-of-concepts(POC).ThisisthesalesjobthatIdid



atIBM.POCengagementsareexpensive.Avendormay

doaPOCifyousayyou'llbuyifit'ssuccessful,ifthey

believethatitwillimprovetheiroddsofclosingthedeal

(usually,basedonsomecompetitiveadvantage),orif

theybelievethatyouwon'tbuywithoutone.Once

you'vecometoatentativedecisionaboutavendor,get

proofthattheproductworks.Payifyoumust.

References.Referencesellingisincreasinglytakingthe

placeofproof-of-concepts.Becautioushere,too.

Hearinganameatavendormeetingisnotthesameas

talkingtothecustomer.You'llalsowanttoknowifthe

customerreceivedanyspecialconsiderationin

exchangeforthereference,andiftheygotanyspecial

supporttomakeaprojectgosmoothly.Unlessyoualso

agreetobeareference,youmaynotgetthesame

support,sotakereferenceswithahugegrainofsalt.

Further,don'tbuywithoutareferencethatyoutrust.



Theclose

Onceyou'reattheendoftheprocess,thevendorcloses

you.Ifyou'vegotspecialnegotiatorsatyourcompany,it's

besttotakeadvantageofthem.Ifyoudon't,thenitmay

payyoutotakeadvantageofanegotiatingclass.Yoursales

repprobablyhas.

That'swhatyou'reupagainst.Youcanusethesalesprocessas

asourceofinformationtomakeaknowledgeabledecision.You

shouldusethemtohelpyoufullyunderstandaparticular

productandareasinwhichthevendorbelievesithasan

advantage.Justdon'tusethesalesprocessasyouronlysource

ofinformation.Andaboveall,don'tmakebuyingdecisions

basedonfriendshipswithsalesreps!Ifyoudoeitherofthese

things,you'llfindatoolboxfullofshiny,expensivegolden

hammers.



5.1.2SomeExamples

Projectteamsacrossthenationhaveshownmemanyexamples

ofgoldenhammers.Fewofthemknewthattheyweremaking

baddecisionsatthetime.Myfavoriteearlyexamplesinclude

C++forateamofCOBOLretreads,VisualBasicforan

inventoryandcontrolsystem,andLotusNotesfora

transactionalairlinereservationsystem.WithJava,we'vegota

wholenewcollectionofpotentialgoldenhammers.



5.1.2.1Java

Javaisoneofthebiggestgoldenhammersthatyou'relikelyto

wield.Youshouldhavemanyothertoolstochoosefrom,

includingscriptinglanguagesandcompetinglanguages.Yet

choosingalternativesoftencarriesastigmathatitdoesn't

deserve.

Someindustrydynamicsarehardformetounderstand.

Microsofttechnologiesbuildricherinterfaceswithmuchless

effortthantheirJavacounterparts,andmanyenterprises

supportnothingbutMicrosoftclients.Yeteveninthisrestricted

environment,mostdeveloperswouldratherwadethroughthe

neck-deepquagmirethatSwinghasbecomeratherthaninject

anyMicrosoftdevelopmentwhereitmakessense.Ontheother

sideofthefence,Microsoftbigotswouldprefertotuneupthat

rustingclunkerthatMicrosoftcallstheirmessageserverandtie

ittogetherwith10-year-oldtransactioncodeinanunmanaged

environment,ducttape,andbailingwireratherthanusea

bettermiddle-tiertechnologylikeoneofdozensofJava

applicationservers.



5.1.2.2J2EE



Mostapplicationsdon'tneedJ2EE.Sunhaseffectivelycarried

theJ2EEbrandintothemainstream.It'shardtofindasimple,

standard-editionapplicationserverandfewcustomersconsider

deployingthatway.Ifyou'veeverbeentaskedwithgettinga

J2EEserveroffoftheground,youknow:it'satedious,

demandingprocessunderthebestofcircumstances.Onthe

otherhand,ifyou'vebeenfortunateenoughtolayoutalotof

moneytobuyawholefleetofthesethings,youmayhavehad

yourvendorinstallitforyou.Whenyoulayoutatonofcash,

theyworkhardtokeepyouhappy.

ButJ2EEisnotthelowestcommondenominator!Many

applicationsshoulddeploywithnothingmorethanaservlet

container,awebserver,andadatabaseconnection.Someof

thefinestandfastestcommercialwebsitesusenothingmore

thanTomcatonApache.



5.1.2.3Distribution

Whenyou'rereadingaboutwebsolutions,youprobablyseeall

kindsofpotentialclusteringstrategiesinthenameofscalability.

Customerswithlargerapplicationsoftensettleondeployinga

clusterofpresentationservers,aclusterofbusinessservers,

andresourceservers.It'satried-and-trueformulathatscales

wellforlargeloads,butit'snottheonlyformula.

Increasingly,expertsarethinkingabouthowtoconsolidate

thesesystemstosavecomplexityandcommunicationscosts.

Often,youcangetawaywithonemiddletiercluster.The

motivationissimple:whenyoubegintoadddistributednodes,

you'reinvitingcomplexityandoverheadintoyourdoor.You

frequentlyinventtheneedtoconnecttonamedservices,

managedistributedtransactions,andcreatesynchronousand

asynchronousmessages.Ihaveseenanynumberofmiddletier

applicationsdesignedwitharcanemultiobjecthierarchies

wrappingasingle,localdatabasetransaction.Itpaysto



occasionallylookateverydistributedtierwithfreshskepticism.

Youcanfrequentlyconsolidateindividualtierswithpotentially

significantgains.Figure5-2showstwoalternativesfor

consolidatingatypicalarchitecture.Onealternativeistodeploy

staticcontentandtheMVCframeworkwiththebusinesstier,

eliminatingtheneedforadistributedfaỗade.Another

alternativeistodeploytheCPU-intensivebusinesstierswitha

RDBMS,whichoftenunderutilizesCPUcycles.



Figure5-2.Sometimesconsolidationoftiers

reducesoverheadandcomplexity



TheimageinthecenterofFigure5-2representsmanytypical

deployments.However,bydeployingthefaỗadelayernextto

yourMVCframework,youcaneliminatetheneedfora

distributedfaỗade.Oneclientofminedidsoandatthesame

timeeliminatedtheneedforaJ2EEserverbyeliminatingthe

needforstatelesssessionbeans.



Anotherstrategy(theright-handsideofFigure5-2)showsthe

deploymentofbusiness-tierlogicwiththeRDBMS.This

deploymentsolvesthreemajorproblems:

Typicalwell-tunedRDBMSserversrarelyusemorethana

smallpercentageofCPUcycles.DeployingaCPU-intensive

businesstiercantakeadvantageofthoseextracyclesfor

intensivedatamarshalling.

Thecommunicationcostsbetweenadatabasetieranda

businessdomainmodelcanbeamongthemostexpensive

inanentireapplication.Deployingthemtogetheralleviates

thisconcern.

Securityishardertomanageacrossawirethanlocally

betweenprocesses.

Thinkaboutitlikethis:ittakesagreatdealofenergyto

confineyourbusinessdomainmodeltothemiddletier.Someof

thelogicinevitablywantstofightitswaytohigherorlower

tiers.Presentationlogicneedsfrequentaccesstovalidation;a

persistentdomainmodelhasatightaffinitywiththedatabase;

faỗadelayersaremuchsimplertocodeanddeployaslocal

interfaces.Ifyoursituationseemstorequireadeviationfrom

thenorm,don'tfightit.



5.1.2.4EJB

EJBisnotsomuchofagoldenhammerasaglasshammer.The

ideamaybeprettytolookat,butit'smuchlessimpressivein

practice.PerhapsnootherJavaAPIhasbeenashypedor

oversoldasEJB.I'vewrittenawholebookonthetopic;Iwon't

rehashithere.Astheyearsgoby,Ispendlesstimetalking

aboutEJBpitfallsandmoretimetalkingaboutwhenEJBshould

beusedatall.ThisbookisaboutmovingawayfromEJBinits



entirety.Still,certainelementsofthatframeworkhavealimited

value.Ifyou'regoingtouseEJB,useitappropriatelyin

situationslikethese:



Faỗades

Ifyouhaveadistributed,transactionalfaỗadethatneedsto

behighlyscalable,considerEJB.Infact,initsoriginal

incarnationEJBsupportedonlystatelesssessionbeans,

withplanstoquicklyaddmessage-drivenbeans.TheEJB

frameworkwastoprovidescalablepoolsofstateless

resources,tocontrolaccesstoscarceresourcesonhigher

tiers.



Thinwrappers

Don'tputtoomuchofyourlogicinsideoftheEJBitself.Use

theEJBasafaỗadeorathinwrapperaroundPOJOobjects

thatdotheactualwork.Thisdesignismuchmoretestable

andeasiertomanage.



Multipleservices

UseEJBonlyfortransactional,distributedproblems.Ifyou

findthatyourfaỗadelayernolongerneedstobe

distributed,don'tusesessionbeansforit.They'reoverkill

foralocalcall.Similarly,don'tuseEJBwhenyouonlyneed

onetokenservice.Wheneverpossible,adoptasimpler

solution.



Noentities



AvoidentitybeansandCMPaltogether.Entitybeansare

unwieldyalbatrossesthattaketremendousenergyto

understand,code,tune,andmaintain.Bettersolutionsare

outthere;findthem.



Nostatefulsessionbeans

Avoidstatefulsessionbeans.You'rebetteroffusingHTTP

sessionsordatabases,dependingonyoursolution.Those

solutionsaremorebroadlyadoptedandwon'ttieyoutoEJB

forthelongterm.



Experiencedteam

ConsiderEJBonlywhenyou'vegotenoughexperienceand

skilltodealwiththeinevitableissues.Don'tkidyourself.

EJBrequiresalotofknowledgeandfinessetopulloff.If

youdon'thaveitonyourteam,getitoruseanother

framework.

ThesearejustafewguidelinesforusingEJBappropriately.But

justtoreiterate,Istronglybelievethatthebestwaytowinthe

EJBgameisnottoplay.



5.1.2.5XML

FewwillarguethatXMLhaschangedthefaceofJava

programmingforever,butnotallofthechangesareforthe

better.XMLdoessolvesomeproblemsverywell,butitalsohas

seriouslimitations.

XMLishard.Ifyou'reagreatprogrammer,youprobablythink

that"hard"isoverstatingit.Youmightprefer"tedious."If



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 5. You Are What You Eat

Tải bản đầy đủ ngay(0 tr)

×