Component Level Design
Component Level Design
Component Level Design
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 PrintJ ob numberOf Pages numberOf Sides paperType magnif ic ation produc tionFeatures design c omponent c omputeJ obCost() passJ obt oPrinter() PrintJ ob c omputeJ ob
initiateJ ob
<<in terf ace>> co mp u teJ o b com ePageCost () put com ePaperCost ( ) put com eProdCost () put com eTot alJ obCost () put
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 ( BPC) --> 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.Thedesignershouldspecifythecomponent inawaythatallowsittobeextendedwithouttheneedtomakeinternal(code orlogiclevel)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.Whensomecharacteristicof anareamustchange,itislikelythatonlythoseclasseswithinthepackage willrequiremodification. TheCommonReusePrinciple(CRP).Classesthatarentreusedtogethershould notbegroupedtogether.Whenoneormoreclasseswithapackagechanges, thereleasenumberofthepackagechanges. 11.2.2ComponentLevelDesignGuidelines Components
11-6
Namingconventionsshouldbeestablishedforcomponentsthatare specifiedaspartofthearchitecturalmodelandthenrefinedand elaboratedaspartofthecomponentlevelmodel Interfaces 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:
Chapter Comments
11-7
Thedegreetowhichacomponentisconnectedtoothercomponents andtotheexternalworld OOview: aqualitativemeasureofthedegreetowhichclassesareconnectedto oneanother.Keepcouplingaslowaspossible. Levelofcoupling 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
11-8
classlibraries;(3)aUMLcollaborationdiagramprovidesanindicationof messagepassingbetweencomponents. Step1.Identifyalldesignclassesthatcorrespondtotheproblemdomain. Step2.Identifyalldesignclassesthatcorrespondtotheinfrastructure domain. Step3.Elaboratealldesignclassesthatarenotacquiredasreusable components. Step3a.Specifymessagedetailswhenclassesorcomponentcollaborate. Step3b.Identifyappropriateinterfacesforeachcomponent. Step3c.Elaborateattributesanddefinedatatypesanddatastructures requiredtoimplementthem. Step3d.Describeprocessingflowwithineachoperationindetail. Step4.Describepersistentdatasources(databasesandfiles)andidentify theclassesrequiredtomanagethem. Step5.Developandelaboratebehavioralrepresentationsforaclassor component. Step6.Elaboratedeploymentdiagramstoprovideadditional implementationdetail. Step7.Factoreverycomponentleveldesignrepresentationandalways consideralternatives.
:ProductionJob
1: buildJob (WOnumber)
2: submitJob (WOnumber)
:WorkOrder :JobQueue
Chapter Comments
11-9
WorkOrder
appropriat e at t ribut es
getJ obDescriiption
buildWorkOrder ()
J obQueue
appropriat e at t ribut es
checkPriority ()
accessPaperDB (weight)
size = B
size = C
size = D
color is custom
color is standard
11-10
Chapter Comments
11-11
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