Tải bản đầy đủ - 0 (trang)
3 Today's Enterprise Applications Have New Requirements

3 Today's Enterprise Applications Have New Requirements

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

1.4WhatIstheStartingPoint?

Sohowdoyouachievesolutionvalue,andhowdoyoubegintoorganize

yourthoughtsonwheretostartinapplicationdevelopment?Ifwehadto

identifythesinglearchitecturalprinciplethatisthefoundationofJ2EE

andattheheartoftheWebSphereproductfamily,wewouldhaveto

chooselayering.Commonly,applicationdevelopmentisaccomplishedin

averticalfashion.Ataminimumthedivisionandestimationofworkis

determinedbydefiningtheapplication'sprimaryuserinterfaces.

Businessrules,behavior,anddataareobtainedandmanipulatedbased

uponactivityconveyedviatheuserinterface.Itistheresponsibilityofthe

architecturetoprovideablueprintthatguidesdevelopersonwhenand

howobjectsaredefinedduringthedevelopmentprocess.The

importanceofestablishingthisblueprintisrealizedinsupportofthe

iterativedevelopmentprocess,whereverticalslicesofapplication

functionalityaredeliverediniterationsmadeupofplanning,

development,andassessmentactivities.Thearchitecturemustsupport

verticalandhorizontaldimensionsofanapplication.Horizontal

developmentactivitiesconsistofapplyinglogging,exceptionhandling,

andstartup/shutdownmechanisms.Basically,thisisbehaviorthatmust

beprovidedbyallapplications.Verticalactivitiesinvolveimplementing

slicesofapplicationfunctionalityfrompresentationtodatasource

access.Havingtheinfrastructureinplacetoallowdevelopmenttooccur

inthesetwodimensionsistheresponsibilityofthearchitecture.

MostexperiencedITprofessionalswillagreethatdevelopingand

adheringtoastandardarchitectureiskeytothesuccessoflarge-scale

softwaredevelopment.ComputersciencepioneerEdsgerDijkstra

validatedthisnotionwhenhedevelopedTHEoperatingsystemin1968.

Sincethen,layeredarchitectureshaveproventheirviabilityin

technologicaldomainssuchashardwareandnetworking.

Layeringhasprovenitselfintheoperatingsystemdomain;however,the

samebenefitsareavailablewhenappliedtoe-commerceorthin-client

orientedapplications.Layeredarchitectureshavebecomeessentialin



supportingtheiterativedevelopmentprocessbypromotingreusability,

scalability,andmaintainability.Nextwewilldefineandjustifyalayered

architectureforJ2EEandWebSpherethatisthefoundationforthe

remainderofthisbook.



1.5WhatIsaLayeredArchitecture?

Whatisalayeredarchitecture,andwhatdoeslayeringmean?

Applicationlayeringistheseparationofarchitecturalconcernswhose

boundariesaresupportedbyinterfacecontracts.Typically,theselayers

arestackedverticallysothateachlayerinteractsonlywiththelayer

directlyunderneathit(Figure1.2).



Figure1.2.Layers.



Becauseaninterfacecontractexistsbetweeneachlayer,changescan

beaffectedonLayer3withminimalsideeffectsonLayer1.Moreover,

Layer3canbetotallyreplaced,aslongasitmeetsLayer2'scontract,

withoutaffectingLayer1.Thispropertyisknownasstrictlayering.

Asmentionedearlier,theprincipleoflayeringiscoretoJ2EEand

WebSphere.FromtheJ2EEperspective,thisconcepthasbeenthe

drivingforcebehindmuchofthestandardsworkthatdefinesthe

platform.Thiscanbeseeninhowpresentationanddataaccessare

designed.TheWebSphereApplicationServerfullyleveragesthis

architecturebyallowingindividuallayerstobescaledanddistributed

independently.

Criticsofstrictlylayeredarchitecturesarguethatperformance,and

sometimesextensibility,aresacrificedsincemoreactivityisrequiredto



propagatedownthroughthelayers.Extensibilitycansufferifcontracts

definedbetweenthelayersarenotrobustenoughtohandlefuture

requirements.However,beingabletostrategicallydistributethe

applicationlayers,usethedomainlayeracrossmultipleapplications,and

easilyconfiguredifferentdatasourcesanduserinterfacesovercomes

suchcriticism.

Nonstrictlayering(Figure1.3)allowshigherlayerstoaccessanylayer

definedbelowitandanswersthecritics'argumentsagainstperformance

andextendibility;however,itnullifiesthebenefitsofstrictlayering.



Figure1.3.Nonstrictlayering.



1.5.1Commonlayeringschemes

Traditionaltwo-tierclient/server-basedapplicationscanbepartitioned

intotwolayerspresentationanddataaccess.Atwo-tierGraphicalUser

Interface(GUI)applicationwouldsimplyqueryadatasource,compute,

anddisplaytheinformationtotheuser.Aconsequenceofthissimple

architectureisthatknowledgeaboutthebusinessdomainisboth

scatteredthroughouttheuserinterface,andisforcedintocomplex

databaseschemas.

Objecttechnologyencouragesnotonlytheabstractionandreuseof

presentationlogic,butalsobusinessprocessesanddata.Therefore,

decouplingapplicationlogicfromapplicationpresentationresultsin

scalablethree-tierdistributedsystemsthatallowsobjectsdefinedto

modelbusinessdataandprocessestobeusedacrossapplication

boundaries.WiththeexplosionoftheInternetandrelatedtechnologies,



enterpriseapplicationrequirementshavemadetheexistenceoflayered

applicationarchitectureimperative.

Themostcommonlayersofanapplicationcanbepartitionedinto

presentation,domain,anddatasourcesections(Figure1.4).Themost

importantlayeristhedomain.Thisiswherebusinessprocessandstate

arecaptured.Presentationlayerobjectseitherconsumeorexercise

domainobjects.Datasourceobjectsdefinedinthedatasourcelayer

accessspecificdatasourcesonbehalfofdomainobjectsrequestingor

savingstate.



Figure1.4.Client/serverlayers.



Itisnotenoughtomerelystipulatethelayersinagraphicandexpect

developerstoproperlypartitionapplicationelementsintoalayered

architecture.Developersmustimplementfunctionalitywithineachlayerin

aconsistentfashion.Moreover,messageinteractionbetweenlayersmust

beformalized.

Formalizinglayerinteractionshouldinvolveadecoupleddesignthat

includesappropriateindirectioninsupportoflayersubstitution.

Additionally,behaviorsprescribedacrossallapplications,namely

exceptionhandling,logging,startup,andshutdownoperations,should

beformalizedandconsistentlyapplied.



1.5.2LayeredArchitectureDefinition



Theprimarymotivationforlayeringistocreateandpreserveareusable

domainmodelthatspansapplicationboundaries.Otheradvantagesto

thisarchitecturearethatithelpsorganizetheprojectandallows

constructionandvalidationofeachlayertovaryindependently.Ofcourse

thiscanbeaccomplishedwiththreelayers;however,introducingtwo

additionallayersbetweenpresentationanddatasourcelayersfurther

decouplesthedomainfromapplicationpresentationanddatasource

requirements(Figure1.5).Anexampleoflayersubstitutionwouldbe

enablingthedomainlayerforpervasivedevicesoravoiceresponseunit.

InFigure1.5,thiswouldimplycreatingonlythenewpresentationlayer

constructsandthenecessarymediatorstointeractwiththeexisting

domainmodel.



Figure1.5.Five-layerarchitecture.



Let'stakeacloserlookateachoftherolesandresponsibilitiesofthe

layersinthisfive-layerarchitecture.



1.5.2.1Presentation

Thepresentationlayerconsistsofobjectsdefinedtoacceptuserinput

anddisplayapplicationoutputs.Themostcommonpresentation

technologiesthatcanbeusedwithJ2EEare:

HTML/JSP(withservletsactingascontrollersasweseeinthenext

section)



XMLandXSLT(againwithservletsactingascontrollers)

Applets(usingAWTorSwing)

Applications(usingAWTorSwing)

Wewilldiscusstherelativemeritsandproperusesofthesetechnologies

inChapter5andrevisitthemwithregardtodeploymentissuesin

Chapter22.Chapters515describethetechnologiesusedindeveloping

presentationandcontrollayersinJ2EE.



1.5.2.2ControllersandMediators

Becauseaprimarygoaloflayeredapplicationsistoenabledomainlogic

tobereusedindifferentpresentations,howtheuserinteractswiththe

businessmodelneedstobeisolated.Thisistheroleofthecontroller.

Whateverthepresentationtechnologyhappenstobe,requestsfor

domainstateandbehaviorwillbedoneviaacontrollerobjectdefinedfor

theparticularpresentationrequirements;e.g.,HTML,Swing,orpervasive

devices.Thiscontrollerobjectimplementsthemediatordesignpattern

from[Gamma].Animportantdesignrequisiteinvolvesmakingsurethat

domain-specificlogicisnotdefinedinpresentationobjectmethods,but

rather,isobtainedfromamediatorreferenceddomainobject.

Additionally,applicationnavigationtopologyisdefinedwithinthislayer.

Applicationpresentationobjectsinteractwithadomainmodelin

generalizedways,regardlessofthepresentationtechnology.For

instance,aGUIwillpresentalistofchoiceswhicharecomposedofa

collectionofdomainmodelobjects;thesamecollectioncanbeusedto

populateanHTMLlist.Forthatmatter,thesamecollectioncouldbeused

toprovidealistofchoicesinavoiceresponseunitinterface(Figure1.6).



Figure1.6.Mediatorsusedbymultiplepresentation

technologies.



Mediatorscaptureanddecoupleapplication-specificfunctionalityfrom

presentationtechnologybyperformingdomainmodelrequestsfor

presentationorcontrollerobjectsthatdriveaspecificapplicationuse

case.Mediatorclassesaredefinedtosatisfyaspecificapplicationuser

interfacefunctionorusecase;therefore,theyarelessgranularthan

controllers.Forexample,asinglemediatorcanbeusedtoimplementa

userregistrationfunctionwithawizard-likeinterface.Mediators

implementbehaviorthatwouldusuallyendupinpresentationclassesas

methods/scripts.Moreover,consistentlyapplyingmediatorobjectsoffers

morethanloosecouplingbetweenadomainmodelandpresentation

technologies.Mediatorsprovideaconvenientandconsistentwayto

transferapplicationstatebetweenuserinterfaces,eliminatingthetypical

highlyparameterizedapproach.Additionally,transactionbehaviorfinds

anappropriatelocationinmediatorobjectssincenavigationandunitsof

workconstraintsaretiedtoapplication-specificfunctionality.

Thekeytomediators'presentationindependenceistheenforcementof

strictlayering,meaningthatmediatorsshouldnotcontainanyreferences

topresentationobjects.However,theyarefreetoreferencedomainobjectpublicstateandbehavior.Caremustalsobetakennottodefine

domain-logicinmediators.Thispitfallcanbeavoidedbyapplyinga

simpleexperiment.Askyourself,"CanIstillperformorobtainthe

requesteddomainoperationusingonlyexistingdomainobjects?"Ifthe

answeris"No,Ineedamediatorobject,"thenthemediatoris

implementingbehaviorthatbelongsinthedomain.



1.5.2.3Domain



Thedomainlayeristhehardestpartofalayeredsystemtounderstand,

andthemostchallengingtoimplement.Tounderstandwhatadomain

objectis,youhavetogobacktothebasicrootsofobject-oriented(OO)

programming.WhenwelearnJavaprogrammingorOO,designthefirst

examplesseenareusuallyintermsofconcreteobjects.Thismightbean

exampleofacontrolsystemlikein[Booch]wheretheobjectsmodeled

arephysicallikeTemperatureSensorsandAirConditioners,oritmightbe

throughasimplegamewhereobjectslikeplayingcardsaremodeled.

Unfortunately,whenmanyprogrammersstartlookingattheirownday-todayproblemstheyinsteadseemoreabstractthingslikewindowsand

databasetables,notthenice,concretethingsseeninthebooksand

tutorials.Thisisunfortunate,sincemodelingtheaspectsofabusinessin

softwarecanbeoneofthemostpowerfultoolsthataprogrammercan

bringtobearonsolvingthehardestproblemsinsoftwaredevelopment.

Capturingbusinessabstractionsinobjectscanmakeasystemmuch

morepowerfulbymakingitmoreflexibleandcancreateacritical

distinctionbetweenthepartsofasystemthatrepresentthebusiness

problembeingsolved(itsessence)andtheaccidentsofimplementation

resultingfromchoicesintechnologythatmightbetransitory.

DomainobjectsareusuallyimplementedasstandardJavaclassesor

plainoldJavaobjects(POJOs).J2EEprovidesanotheroptionfor

implementingdomainobjectsthatwewillexaminemorecloselyinlater

chapters.Aprogrammercanchoosetoimplementhisdomainobjectsas

EnterpriseJavaBeans(EJBs),whichconveyssomebenefitsintermsof

distribution,transactioncapabilities,andpersistence.EvenwhenEJBs

areused,amixofstandardJavaclassesandEJBsshouldbeemployed,

aswewillexamineingreaterdetailinChapters19and30.



1.5.2.4Mapping

Aconsequenceofbuildingadomainlayer,aswehavedescribed,isthat

itshouldnotbeconcernedwithpurelyimplementation-specificdetails.

Forinstance,oneofthemostcommonquestionsinenterprise

programmingishowtoextractdatafromorupdatedatainadatabase.



Ratherthanmakingthisbehaviorpartofthedomainobject,asecondset

ofobjectsisrequiredtoperformthisfunction.Separatingthebehaviorin

thiswayconveysanumberofbenefits,includingmakingitpossibleto

changeimplementationdetailslikedatabasevendorordatabaseschema

withoutchangingthedomainimplementation.

Adesignlikethisrequiresaseparatelayer,oftencalledmappingor

persistence,thatcanmovedatafromdomainobjectstoback-enddata

sourcesandviceversa.Thereareseveralopensourceandcommercial

products,likeApacheCastor,CrossLogic'sUniverse,andOracle's

TopLinkthatcanaddthisbehavior.However,foraprogrammerusing

J2EE,thecommonwaythatthisbehaviorwillbeusedisthroughthe

APIsprovidedbytheEJBcontainer.AswewilldescribeinChapters19

and23,theEJBcontainerinWebSphereprovidesasimpleand

consistentinterfacefordatapersistenceusingentitybeans.However,we

maystillneedtoimplementsomemappingfunctionsevenindesigns

usingEJBswhenweneedtomovedatabetweenJavaBeansandEJBs.

Wewillcoverthistopicin-depthinalaterchapter.



1.5.3DataSourceAccess

Atsomepointinyourapplication,youhavetoretrieveandstoredata,or

communicatewithexternalsystems.Undoubtedlyrelationaldatabases

(DB2,Oracle,Informix,etc.)arethemostcommonwayITorganizations

storeandqueryenterprisedata.Recognizingthisprofoundmarketshare,

SundeliveredtheJDBC(JavaDatabaseConnectivity)API.JDBCallows

theproductionandexecutionofvendor-neutralStructuredQuery

Language(SQL).[1]DeveloperscanusestandardANSISQLagainstany

JDBC-compliantdriver.ThespecificAPIandtypesofavailableJDBC

driversarebeyondthescopeofthisdiscussion;refertotheJDBC

specification,availableonSun'sJavaWebsite(http://www.java.com),for

moreinformation.

[1]TheJDBCspecificationalsoappliestononrelationaldatasources.



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

3 Today's Enterprise Applications Have New Requirements

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

×