Você está na página 1de 11

Chapter Comments

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

SEPA, 6/e Instructors Guide

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

elaborated design class PrintJ ob


num berOf Pages num berOf Sides paperType paperWeight paperSize paperColor m agnif icat ion colorRequirem ents productionFeatures collat ionOpt ions bindingOptions coverSt ock bleed priority tot alJ obCost WOnum ber com ePageCost ( ) put com ePaperCost ( ) put com eProdCost () put com eTot alJ obCost ( ) put buildWorkOrder() checkPriority () passJ obto Production()

<<in terf ace>> initiateJ o b buildWorkOrder() checkPriorit y () passJ obto Production( )

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

SEPA, 6/e Instructors Guide

design component getJ obData ComputePageCost

accessCostsDB

elaborated module PageCost


in: numberPages in: numberDocs in: sides= 1, 2 in: color= 2, 3, 4 1, in: page size = A, B, C, B out : page cost in: job size in: color= 2, 3, 4 1, in: pageSize = A, B, C, B out : BPC out : SF get J obDat a ( numberPages,numberDocs, sides, color, pageSize, pageCost ) accessCost sDB (jobSize, color, pageSize, BPC, SF) comput ePageCost ) (

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

SEPA, 6/e Instructors Guide

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

SEPA, 6/e Instructors Guide

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

computeJ ob PrintJ ob initiateJ ob

WorkOrder
appropriat e at t ribut es

getJ obDescriiption

buildWorkOrder ()

buildJ ob ProductionJ ob submitJ ob

<< interface>> initiateJ ob


passJ obToProduction( )

J obQueue
appropriat e at t ribut es

checkPriority ()

validate attributes input

accessPaperDB (weight)

returns baseC ostperPage paperC ostperPage = baseC ostperPage

size = B

paperC ostperPage = paperC ostperPage * 1 .2

size = C

paperC ostperPage = paperC ostperPage * 1 .4

size = D

paperC ostperPage = paperC ostperPage * 1 .6

color is custom

paperC ostperPage = paperC ostperPage * 1 .1 4

color is standard

returns ( paperC ostperPage )

11-10

SEPA, 6/e Instructors Guide

Chapter Comments

11-11

behavior wit hin the st at e buildingJ obDat a dat aInput Incomplet e

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

computingJ obCost entry/ computeJ ob exit/ save totalJ obCost

jobCost Accept ed [ cust omer is aut horized] / get Elect ronicSignat ure

formingJ ob entry/ buildJ ob exit/ save WOnumber do/

submittingJ ob entry/ submitJ ob exit/initiateJ ob do/ place on J obQueue

jobSubmit t ed[ all aut horizat ions acquired]/ print WorkOrder

Você também pode gostar