您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 工程监理 > 软件工程-实践者的研究方法(9)
1Chapter10Component-LevelDesignSoftwareEngineering:APractitioner’sApproach,7/ebyRogerS.Pressman2WhatisaComponent?OMGUnifiedModelingLanguageSpecification[OMG01]definesacomponentas“…amodular,deployable,andreplaceablepartofasystemthatencapsulatesimplementationandexposesasetofinterfaces.””OOview:acomponentcontainsasetofcollaboratingclassesConventionalview:acomponentcontainsprocessinglogic,theinternaldatastructuresthatarerequiredtoimplementtheprocessinglogic,andaninterfacethatenablesthecomponenttobeinvokedanddatatobepassedtoit.3OOComponentPrintJobcomputeJobinitiateJobnumberOfPagesnumberOfSidespaperTypepaperWeightpaperSizepaperColormagnificationcolorRequirementsproductionFeaturescollationOptionsbindingOptionscoverStockbleedprioritytotalJobCostWOnumberPrintJobcomputePageCost()computePaperCost()computeProdCost()computeTotalJobCost()buildWorkOrder()checkPriority()passJobtoProduction()elaborateddesignclassinterfacecomputeJobcomputePageCost()computePaperCost()computeProdCost()computeTotalJobCost()interfaceinitiateJobbuildWorkOrder()checkPriority()passJobtoProduction()designcomponentnumberOfPagesnumberOfSidespaperTypemagnificationproductionFeaturesPrintJobcomputeJobCost()passJobtoPrinter()analysisclass4ConventionalComponent5ConventionalComponentComputePageCostdesigncomponentaccessCostsDBgetJobDataelaboratedmodulePageCostin:jobsizein:color=1,2,3,4in:pageSize=A,B,C,Bout:BPCout:SFin:numberPagesin:numberDocsin:sides=1,2in:color=1,2,3,4in:pagesize=A,B,C,Bout:pagecostjobsize(JS)=numberPages*numberDocs;lookupbasepagecost(BPC)--accessCostsDB(JS,color);lookupsizefactor(SF)--accessCostDB(JS,color,size)jobcomplexityfactor(JCF)=1+[(sides-1)*sideCost+SF]pagecost=BPC*JCFgetJobData(numberPages,numberDocs,sides,color,pageSize,pageCost)accessCostsDB(jobSize,color,pageSize,BPC,SF)computePageCost()6BasicDesignPrinciplesOpen-ClosedPrinciple(开闭原则).“Amodule[component]shouldbeopenforextensionbutclosedformodification.SubstitutionPrinciple(替换原则).“Subclassesshouldbesubstitutablefortheirbaseclasses.DependencyInversionPrinciple(依赖倒置原则).“Dependonabstractions.Donotdependonconcretions(具体实现).”InterfaceSegregationPrinciple(接口分离原则).“Manyclient-specificinterfaces(专用接口)arebetterthanonegeneralpurposeinterface.ReleaseReuseEquivalencyPrinciple(发布复用等价原则).“Thegranule(粒度)ofreuseisthegranuleofrelease.”CommonClosurePrinciple(共同封装原则).“Classesthatchangetogetherbelongtogether.(同时变更的类应封装在一起)”CommonReusePrinciple(共同重用原则).“Classesthataren’treusedtogethershouldnotbegroupedtogether.”7DesignGuidelinesComponentsNamingconventionsshouldbeestablishedforcomponentsthatarespecifiedaspartofthearchitecturalmodelandthenrefinedandelaboratedaspartofthecomponent-levelmodelInterfacesInterfacesprovideimportantinformationaboutcommunicationandcollaboration(aswellashelpingustoachievetheOPC)DependenciesandInheritanceitisagoodideatomodeldependenciesfromlefttorightandinheritancefrombottom(derivedclasses)totop(baseclasses).8Cohesion(内聚度)Conventionalview:the“single-mindedness”ofamoduleOOview:cohesionimpliesthatacomponentorclassencapsulatesonlyattributesandoperationsthatarecloselyrelatedtooneanother.Levelsofcohesion(内聚度依次递减)FunctionalLayerCommunicationalSequentialProceduralTemporal设计目标:模块内各动作的内聚度越高越好。9Coupling(耦合度)Conventionalview:ThedegreetowhichamoduleisconnectedtoothermodulesandtotheexternalworldOOview:aqualitativemeasureofthedegreetowhichclassesareconnectedtooneanotherLevelofcoupling(耦合度依次递减)ContentCommonControlDataRoutinecallExternal设计目标:模块之间的耦合度越底越好。10ComponentLevelDesign-IStep1.Identifyalldesignclassesthatcorrespondtotheproblemdomain.Step2.Identifyalldesignclassesthatcorrespondtotheinfrastructuredomain.(forexample,GUIcomponent,OScomponents)Step3.Elaboratealldesignclassesthatarenotacquiredasreusablecomponents,includingthemessage,interface,attributeandoperation.Step3a.Specifymessagedetailswhenclassesorcomponentcollaborate.(CollaborationDiagramwithmessagesisshown)11ComponentLevelDesign-IStep3b.Identifyappropriateinterfacesforeachcomponent.下图为PrintJob重构类和接口定义Step3c.Elaborateattributesanddefinedatatypesanddatastructuresrequiredtoimplementthem.12Component-LevelDesign-IIStep3d.Describeprocessingflowwithineachoperationindetail.实例:右图为ComputePaperCost()操作的ActivityDiagram.13Component-LevelDesign-IIIStep4.Describedatasources(database)andidentifytheclassesrequiredtomanagethem.Step5.Developandelaboratebehavioralrepresentationsforaclassorcomponent.(右图为PrintJob类的StateChart)Step6.Elaboratedeploymentdiagramstoprovideadditionalimplementationdetail.14AlgorithmDesignModelrepresentsthealgorithmatalevelofdetailthatcanbereviewedforqualityoptions:decisiontable/treegraphical(e.g.flowchart,boxdiagram)PAD(ProgramAnalysisDiagram)pseudocode(e.g.PDL)15DecisionTableConditionsregularcustomersilvercustomergoldcustomerspecialdiscountRulesnodiscountapply8percentdiscountapply15percentdiscountapplyadditionalxpercentdiscountTFTTTTTF13564FTTT2Rules2019/8/916Flowchart17NS(Box)Diagram18ProgramAnalysisDiagram(PAD)19ProgramAnalysisDiagram(PAD)例:模块binary(x,v,n,p)完
本文标题:软件工程-实践者的研究方法(9)
链接地址:https://www.777doc.com/doc-212980 .html