1Chapter8DesignConceptsSoftwareEngineering:APractitioner’sApproach,7/ebyRogerS.Pressman2DesignGoodsoftwaredesignshouldexhibit:Firmness(稳定性):Aprogramshouldnothaveanybugsthatinhibititsfunction.Commodity(适用性):Aprogramshouldbesuitableforthepurposesforwhichitwasintended.Delight(令人愉快):Theexperienceofusingtheprogramshouldbepleasurableone.3AnalysisModel=DesignModelAnalysisModeluse-cases-textuse-casediagramsactivitydiagramsswimlanediagramsdataflowdiagramscontrol-flowdiagramsprocessingnarrativesflow-orientedelementsbehavioralelementsclass-basedelementsscenario-basedelementsclassdiagramsanalysispackagesCRCmodelscollaborationdiagramsstatediagramssequencediagramsData/ClassDesignArchitecturalDesignInterfaceDesignComponent-LevelDesignDesignModel43CharactersofDesignQualitythedesignmustimplementalloftheexplicit(明确的)requirementscontainedintheanalysismodel,anditmustaccommodatealloftheimplicit(隐含的)requirementsdesiredbythecustomer.thedesignmustbeareadable,understandableguideforthosewhogeneratecodeandforthosewhotestandsubsequentlysupportthesoftware.thedesignshouldprovideacompletepicture(全貌)ofthesoftware,addressingthedata,functional,andbehavioraldomainsfromanimplementationperspective.5QualityGuidelinesAdesignshouldexhibitanarchitecturethat(1)hasbeencreatedusingrecognizablearchitecturalstylesorpatterns,(2)iscomposedofcomponentsthatexhibitgooddesigncharacteristicsand(3)canbeimplementedinanevolutionaryfashionAdesignshouldbemodular;thatis,thesoftwareshouldbelogicallypartitionedintoelementsorsubsystemsAdesignshouldcontainrepresentationsofdata,architecture,interfaces,andcomponents.Adesignshouldleadtodatastructuresthatareappropriatefortheclassestobeimplemented.Adesignshouldleadtocomponentsthatexhibitindependentfunctionalcharacteristics.Adesignshouldleadtointerfacesthatreducethecomplexityofconnectionsbetweencomponentsandwiththeexternalenvironment.Adesignshouldbederivedusingarepeatablemethodthatisdrivenbyinformationobtainedduringsoftwarerequirementsanalysis.Adesignshouldberepresentedusinganotationthateffectivelycommunicatesitsmeaning.6DesignPrinciplesThedesignshouldbetraceabletotheanalysismodel.Thedesignshouldnotreinvent(彻底改造)thewheel.Thedesignshould“minimizethedistance”betweenthesoftwareandtheproblemasitexistsintherealworld.Thedesignshouldexhibituniformityandintegration.Thedesignshouldbestructuredtoaccommodatechange.Thedesignshouldbeassessedforqualityasitisbeingcreated,notafterthefact.Thedesignshouldbereviewedtominimizeconceptual(semantic)errors.Designisnotcoding,codingisnotdesign.FromDavis[DAV95]7FundamentalConceptsAbstraction—data,procedureArchitecture(架构)—theoverallstructureofthesoftwarePatterns—conveys(承载)theessence(精髓)ofaprovendesignsolutionModularity—compartmentalization(划分)ofdataandfunctionInformationhiding—controlledinterfacesFunctionalindependence—single-mindedfunctionandlowcouplingAspects—amechanismforunderstandinghowglobalrequirementsaffectdesignRefactoring(重构)—areorganizationtechniquethatsimplifiesthedesignDesignClasses—providedesigndetailthatwillenableanalysisclassestobeimplemented8DataAbstractiondoorimplementedasadatastructuremanufacturermodelnumbertypeswingdirectioninsertslightsweightopeningmechanism9ProceduralAbstractionopenimplementedwithaknowledgeoftheobjectthatisassociatedwithenterdetailsofenteralgorithm10Architecture“Theoverallstructureofthesoftwareandthewaysinwhichthatstructureprovidesconceptualintegrityforasystem.”Structuralproperties.Thisaspectofthearchitecturaldesignrepresentationdefinesthecomponentsofasystem(e.g.,modules,objects)andthemannerinwhichthosecomponentsarepackagedandinteractwithoneanother.Forexample,objectsencapsulatebothdataandtheprocessingthatmanipulatesthedata.Extra-functionalproperties.Thearchitecturaldesigndescriptionshouldaddresshowthedesignarchitectureachievesrequirementsforperformance,capacity,reliability,security,adaptability,andothersystemcharacteristics.Families(族)ofrelatedsystems.Thearchitecturaldesignshoulddrawuponrepeatablepatternsthatarecommonlyencounteredinthedesignoffamiliesofsimilarsystems.Thedesignshouldhavetheabilitytoreusearchitecturalbuildingblocks.11ArchitectureInthesimplestform,architectureisthestructureororganizationofprogramcomponents(modules),themannerinwhichthesecomponentsinteract,andthestructureofdatathatareusedbythecomponents.Inabroadersense,componentscanbegeneralizedtorepresentmajorsystemelementsandtheirinteractions.本地子系统远端子系统图像采集机器人控制系统图像压缩图像发送图像处理任务处理命令接收机器人控制图像处理任务处理图像接收图像还原任务调度生成控制命令命令发送12Modularitymodularityisthesingleattributeofsoftwarethatallowsaprogramtobeintellectuallymanageable.Monolithic(整块庞大的)software(i.e.,alargeprogramcomposedofasinglemodule)cannotbeeasilygrasped()byasoftwareengineer.Thenumberofcontrolpaths,spanofreference(引用跨度),numberofvariables,andoverallcomplexitywouldmakeunderstandingclosetoimpossible.Inalmostallinstances,youshouldbreakthedesignintomanymodules,hopingtomakeunderstandingeasierandasaconsequence,reducethecostrequiredtobuildthesoftware.13Modularity:numberofmodulesWhatistherightnumberofmodulesforaspecifics