Beruflich Dokumente
Kultur Dokumente
11-1
Chapter
11
ComponentLevelDesign
CHAPTEROVERVIEWANDCOMMENTS Thischapterdiscussestheportionofthesoftwaredevelopmentprocesswhere thedesigniselaboratedandtheindividualdataelementsandoperationsare designedindetail.First,differentviewsofacomponentareintroduced. Guidelinesforthedesignofobjectorientedandtraditional(conventional) programcomponentsarepresented. 11.1 WhatisaComponent? Thissectiondefinesthetermcomponentanddiscussesthedifferencesbetween objectoriented,traditional,andprocessrelatedviewsofcomponentleveldesign. ObjectManagementGroupOMGUMLdefinesacomponentasamodular, deployable,andreplaceablepartofasystemthatencapsulatesimplementation andexposesasetofinterfaces. 11.1.1AnObjectOrientedView OOview:acomponentcontainsasetofcollaboratingclasses. Eachclasswithinacomponenthasbeenfullyelaboratedtoincludeallattributes andoperationsthatarerelevanttoitsimplementation.Aspartofthedesign elaboration,allinterfaces(messages)thatenabletheclassestocommunicateand collaboratewithotherdesignclassesmustalsobedefined.Toaccomplishthis, thedesignerbeginswiththeanalysismodelandelaboratesanalysisclasses(for componentsthatrelatetotheproblemdomain)andinfrastructureclasses(or componentsthatprovidesupportservicesfortheproblemdomain). FigurebelowshowsExampleofElaborationofadesigncomponent.
11-2
analysis c lass Print J ob numberOf Pages numberOf Sides paperType magnif ic at ion produc tionFeat ures design c omponent c omputeJ obCost( ) passJ obt oPrint er( ) c omput eJ ob
Print J ob
initiat eJ ob
<<in terf ace>> co mp u teJ o b com putePageCost ( ) com putePaperCost ( ) com puteProdCost () com puteTot alJ obCost ( )
<<in terf ace>> in it iat eJ o b buildWorkOrder( ) checkPriorit y () passJ obt o Product ion( )
Chapter Comments
11-3
11.1.2TheConventionalView Conventionalview:acomponentisafunctionalelementofaprogramthat incorporatesprocessinglogic,theinternaldatastructuresthatarerequiredto implementtheprocessinglogic,andaninterfacethatenablesthecomponentto beinvokedanddatatobepassedtoit. Aconventionalcomponent,alsocalledamodule,resideswithinthes/w architectureandservesoneofthreeimportantrolesas: 1. Acontrolcomponentthatcoordinatestheinvocationofallotherproblem domaincomponents, 2. Aproblemdomaincomponentthatimplementsacompleteorpartialfunction thatisrequiredbythecustomer, 3. Aninfrastructurecomponentthatisresponsibleforfunctionsthatsupportthe processingrequiredintheproblemdomain. Exampleofastructurechartforaconventionalsystem:
11-4
accessCostsDB
job size ( J S) = numberPages * numberDocs; lookup base page cost ( BP C) --> accessCost sDB ( J S, color) ; lookup size fact or ( SF) --> accessCost DB ( J S, color, size) job complexit y fact or ( J CF) = 1 + [ ( sides-1) * sideCost + SF] pagecost = BPC * J CF
Chapter Comments
11-5
11.2DesigningClassBasedComponents TheseprinciplescanbeusedtoguidethedesigneraseachS/Wcomponentis developed. TheOpenClosedPrinciple(OCP).Amodule[component]shouldbeopenfor extensionbutclosedformodification.Thedesignershouldspecifythe componentinawaythatallowsittobeextendedwithouttheneedtomake internal(codeorlogiclevel)modificationstothecomponent. TheLiskovSubstitutionPrinciple(LSP).Subclassesshouldbesubstitutable fortheirbaseclasses.Acomponentthatusesabaseclassshouldcontinueto functionproperlyifaclassderivedfromthebaseclassispassedtothe componentinstead. DependencyInversionPrinciple(DIP).Dependonabstractions.Donot dependonconcretions.Abstractionsaretheplacewhereadesigncanbe extendedwithoutgreatcomplications. TheInterfaceSegregationPrinciple(ISP).Manyclientspecificinterfacesare betterthanonegeneralpurposeinterface.Thedesignershouldcreatea specializedinterfacetoserveeachmajorcategoryofclients. TheReleaseReuseEquivalencyPrinciple(REP).Thegranuleofreuseisthe granuleofrelease.Whenclassesorcomponentsaredesignedforreuse,there isanimplicitcontractthatisestablishedbetweenthedeveloperofthe reusableentityandthepeoplewhowilluseit. TheCommonClosurePrinciple(CCP).Classesthatchangetogetherbelong together.Classesshouldbepackagedcohesively.Whensomecharacteristic ofanareamustchange,itislikelythatonlythoseclasseswithinthepackage willrequiremodification. TheCommonReusePrinciple(CRP).Classesthatarentreusedtogether shouldnotbegroupedtogether.Whenoneormoreclasseswithapackage changes,thereleasenumberofthepackagechanges. 11.2.2ComponentLevelDesignGuidelines Components Namingconventionsshouldbeestablishedforcomponentsthatare specifiedaspartofthearchitecturalmodelandthenrefinedand elaboratedaspartofthecomponentlevelmodel Interfaces
11-6
Interfacesprovideimportantinformationaboutcommunication andcollaboration(aswellashelpingustoachievetheOCP) DependenciesandInheritance Itisagoodideatomodeldependenciesfromlefttorightand inheritancefrombottom(derivedclasses)totop(baseclasses). 11.2.3Cohesion Cohesionimpliesthatacomponentorclassencapsulatesonlyattributesand operationsthatarecloselyrelatedtooneanotherandtotheclassorcomponent itself. Levelsofcohesion Functional:occurswhenamoduleperformsoneandonlyone computationandthenreturnsaresult. Layer:occurswhenahigherlayeraccessestheservicesofalower layer,butlowerlayersdonotaccesshigherlayers. Communicational:Alloperationsthataccessthesamedataaredefined withinoneclass. Sequential:Componentsoroperationsaregroupedinamannerthat allowsthefirsttoprovideinputtothenextandsoon. Procedural:Componentsoroperationsaregroupedinamannerthat allowsonetobeinvokedimmediatelyaftertheprecedingonewas invoked. Temporal:Operationsthatareperformedtoreflectaspecificbehavior orstate. Utility:Components,classes,oroperationsthatexistwithinthesame categorybutareotherwiseunrelatedaregroupedtogether. 11.2.4Coupling Conventionalview: Thedegreetowhichacomponentisconnectedtoothercomponents andtotheexternalworld OOview: aqualitativemeasureofthedegreetowhichclassesareconnectedto oneanother.Keepcouplingaslowaspossible. Levelofcoupling
Chapter Comments
11-7
Content:Occurswhenonecomponentsuperstitiouslymodifiesdata thatisinternaltoanothercomponent.ViolatesInformationhiding Common:Occurswhenanumberofcomponentsallmakeuseofa globalvariable. Control:OccurswhenoperationA()invokesoperationB()andpassesa controlflagtoB.ThecontrolflagthendirectslogicalflowwithinB. Stamp:OccurswhenClassBisdeclaredasatypeforanargumentof anoperationofClassA.BecauseClassBisnowapartofthedefinition ofClassA,modifyingthesystembecomesmorecomplex. Data:Occurswhenoperationspasslongstringsofdataarguments. Testingandmaintenancebecomesmoredifficult. Routinecall:Occurswhenoneoperationinvokesanother. Typeuse:OccurswhencomponentAusesadatatypedefinedin componentB. Inclusionorimport:OccurswhencomponentAimportsorincludesa packageorthecontentofcomponentB. External:Occurswhenacomponentcommunicatesorcollaborates withinfrastructurecomponents(O/Sfunction). 11.3ConductingComponentLevelDesign Thestepsdiscussedinthissectionprovideareasonabletasksetfordesigninga component.Youshouldemphasizethat(1)designclassesintheproblemdomain areusuallycustomdesigned,however,ifanorganizationhasencourageddesign forreuse,theremaybeanexistingcomponentthatfitsthebill;(2)designclasses correspondingtotheinfrastructuredomaincansometimesbeoftenfromexisting classlibraries;(3)aUMLcollaborationdiagramprovidesanindicationof messagepassingbetweencomponents. Step1.Identifyalldesignclassesthatcorrespondtotheproblemdomain. Step2.Identifyalldesignclassesthatcorrespondtotheinfrastructure domain. Step3.Elaboratealldesignclassesthatarenotacquiredasreusable components. Step3a.Specifymessagedetailswhenclassesorcomponentcollaborate. Step3b.Identifyappropriateinterfacesforeachcomponent.
11-8
Step3c.Elaborateattributesanddefinedatatypesanddatastructures requiredtoimplementthem. Step3d.Describeprocessingflowwithineachoperationindetail. Step4.Describepersistentdatasources(databasesandfiles)andidentify theclassesrequiredtomanagethem. Step5.Developandelaboratebehavioralrepresentationsforaclassor component. Step6.Elaboratedeploymentdiagramstoprovideadditional implementationdetail. Step7.Factoreverycomponentleveldesignrepresentationandalways consideralternatives.
:P o u t n b r d c io Jo
1 b ild b : u Jo
( W n me Ou b r
2 s b it b : u m Jo
( W n me Ou b r
:W r Od r ok r e :Jo Q e e b uu
WorkOrder
appropriate attributes
getJ obDescriiption
buildWorkOrder ()
J obQueue
appropriate attributes
checkPriority ()
Chapter Comments
11-9
size = B
size = C
size = D
color is custom
color is standard
11-10
buildingJ obData entry/ readJ obData () exit/displayJ obData () do/ checkConsistency() include/ dataInput
dat aInput Complet ed [ all dat a it ems consist ent ] / displayUserOpt ions
jobCost Accept ed [ cust omer is aut horized] / get Elect ronicSignat ure