软件工程-实践者的研究方法(9)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1Chapter10Component-LevelDesignSoftwareEngineering:APractitioner’sApproach,7/ebyRogerS.Pressman2WhatisaComponent?OMGUnifiedModelingLanguageSpecification[OMG01]definesacomponentas“…amodular,deployable,andreplaceablepartofasystemthatencapsulatesimplementationandexposesasetofinterfaces.””OOview:acomponentcontainsasetofcollaboratingclassesConventionalview: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()6BasicDesignPrinciplesOpen-ClosedPrinciple(开闭原则).“Amodule[component]shouldbeopenforextensionbutclosedformodification.SubstitutionPrinciple(替换原则).“Subclassesshouldbesubstitutablefortheirbaseclasses.DependencyInversionPrinciple(依赖倒置原则).“Dependonabstractions.Donotdependonconcretions(具体实现).”InterfaceSegregationPrinciple(接口分离原则).“Manyclient-specificinterfaces(专用接口)arebetterthanonegeneralpurposeinterface.ReleaseReuseEquivalencyPrinciple(发布复用等价原则).“Thegranule(粒度)ofreuseisthegranuleofrelease.”CommonClosurePrinciple(共同封装原则).“Classesthatchangetogetherbelongtogether.(同时变更的类应封装在一起)”CommonReusePrinciple(共同重用原则).“Classesthataren’treusedtogethershouldnotbegroupedtogether.”7DesignGuidelinesComponentsNamingconventionsshouldbeestablishedforcomponentsthatarespecifiedaspartofthearchitecturalmodelandthenrefinedandelaboratedaspartofthecomponent-levelmodelInterfacesInterfacesprovideimportantinformationaboutcommunicationandcollaboration(aswellashelpingustoachievetheOPC)DependenciesandInheritanceitisagoodideatomodeldependenciesfromlefttorightandinheritancefrombottom(derivedclasses)totop(baseclasses).8Cohesion(内聚度)Conventionalview:the“single-mindedness”ofamoduleOOview:cohesionimpliesthatacomponentorclassencapsulatesonlyattributesandoperationsthatarecloselyrelatedtooneanother.Levelsofcohesion(内聚度依次递减)FunctionalLayerCommunicationalSequentialProceduralTemporal设计目标:模块内各动作的内聚度越高越好。9Coupling(耦合度)Conventionalview:ThedegreetowhichamoduleisconnectedtoothermodulesandtotheexternalworldOOview:aqualitativemeasureofthedegreetowhichclassesareconnectedtooneanotherLevelofcoupling(耦合度依次递减)ContentCommonControlDataRoutinecallExternal设计目标:模块之间的耦合度越底越好。10ComponentLevelDesign-IStep1.Identifyalldesignclassesthatcorrespondtotheproblemdomain.Step2.Identifyalldesignclassesthatcorrespondtotheinfrastructuredomain.(forexample,GUIcomponent,OScomponents)Step3.Elaboratealldesignclassesthatarenotacquiredasreusablecomponents,includingthemessage,interface,attributeandoperation.Step3a.Specifymessagedetailswhenclassesorcomponentcollaborate.(CollaborationDiagramwithmessagesisshown)11ComponentLevelDesign-IStep3b.Identifyappropriateinterfacesforeachcomponent.下图为PrintJob重构类和接口定义Step3c.Elaborateattributesanddefinedatatypesanddatastructuresrequiredtoimplementthem.12Component-LevelDesign-IIStep3d.Describeprocessingflowwithineachoperationindetail.实例:右图为ComputePaperCost()操作的ActivityDiagram.13Component-LevelDesign-IIIStep4.Describedatasources(database)andidentifytheclassesrequiredtomanagethem.Step5.Developandelaboratebehavioralrepresentationsforaclassorcomponent.(右图为PrintJob类的StateChart)Step6.Elaboratedeploymentdiagramstoprovideadditionalimplementationdetail.14AlgorithmDesignModelrepresentsthealgorithmatalevelofdetailthatcanbereviewedforqualityoptions:decisiontable/treegraphical(e.g.flowchart,boxdiagram)PAD(ProgramAnalysisDiagram)pseudocode(e.g.PDL)15DecisionTableConditionsregularcustomersilvercustomergoldcustomerspecialdiscountRulesnodiscountapply8percentdiscountapply15percentdiscountapplyadditionalxpercentdiscountTFTTTTTF13564FTTT2Rules2019/8/916Flowchart17NS(Box)Diagram18ProgramAnalysisDiagram(PAD)19ProgramAnalysisDiagram(PAD)例:模块binary(x,v,n,p)完

1 / 39
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功