chObjectOrientedDesignPrinciples实用实用教案

上传人:新** 文档编号:568588278 上传时间:2024-07-25 格式:PPT 页数:54 大小:2.23MB
返回 下载 相关 举报
chObjectOrientedDesignPrinciples实用实用教案_第1页
第1页 / 共54页
chObjectOrientedDesignPrinciples实用实用教案_第2页
第2页 / 共54页
chObjectOrientedDesignPrinciples实用实用教案_第3页
第3页 / 共54页
chObjectOrientedDesignPrinciples实用实用教案_第4页
第4页 / 共54页
chObjectOrientedDesignPrinciples实用实用教案_第5页
第5页 / 共54页
点击查看更多>>
资源描述

《chObjectOrientedDesignPrinciples实用实用教案》由会员分享,可在线阅读,更多相关《chObjectOrientedDesignPrinciples实用实用教案(54页珍藏版)》请在金锄头文库上搜索。

1、1.Object-OrientedDesign:BridgingfromAnalysistoImplementationSystemsdesignisthebridgebetweenuserrequirementsandprogrammingthenewsystem.Onestrengthoftheobject-orientedapproachisthatthedesignmodelsareoftenjustextensionsoftherequirementsmodels.Obviously,itismucheasiertoextendanexistingmodelthantocreatee

2、ntirelynewdesignmodels.OnetenetofAgile,adaptiveapproachestodevelopmentistocreatemodelsonlyiftheyhavemeaningandarenecessary.Thedesignmodelsmaynotbeformalizedintoacomprehensivesetofdocumentsanddiagrams,buttheyarecertainlynecessary.2024/7/25第1页/共53页第一页,共54页。1.1OverviewofObject-OrientedProgramsAnobject-

3、orientedprogramconsistsofasetofprogramobjectsthatcooperatetoaccomplisharesult.Eachprogramobjecthasprogramlogicandanynecessaryattributesencapsulatedintoasingleunit.Theseobjectsworktogethebysendingeachothermessagesandworkinginconcerttosupportthefunctionsofthemainprogram.2024/7/25第2页/共53页第二页,共54页。1.1Ov

4、erviewofObject-OrientedPrograms2024/7/25第3页/共53页第三页,共54页。1.1OverviewofObject-OrientedProgramsAnobject-orientedsystemconsistsofsetsofcomputingobjects.Eachobjecthasdataandprogramlogicencapsulatedwithinitself.Thisiscalledaninstantiationoftheclassthatis,makinganinstance(anobject)basedonthetemplateprovid

5、edbytheclassdefinition.Eachobjectalsorepresentsastructureofthree-layerarchitecture.2024/7/25第4页/共53页第四页,共54页。1.2Object-OrientedDesignModelsandProcesses2024/7/25第5页/共53页第五页,共54页。1.2Object-OrientedDesignModelsandProcessesThedomainmodelclassdiagramidentifiesalltheclasses,or“things,”thatareimportantinth

6、eproblemdomain.Theusecasediagramsidentifiedtheelementarybusinessprocessesthatthesystemneedstosupportinotherwords,allthewaysuserswanttousethesystemtocarryoutprocessinggoals.Theactivitydiagramsandusecasedescriptionsdocumenttheinternalworkflowofeachusecase.2024/7/25第6页/共53页第六页,共54页。1.2Object-OrientedDe

7、signModelsandProcessesAnactivitydiagramshowsthestepsnecessarytocarryoutaparticularusecase.Thesystemsequencediagramsarecloselyrelatedtoactivitydiagrams,exceptthattheyshowthemessagesordatathataresentbackandforthbetweentheuserandthesystemduringthestepsoftheusecase.Finally,statemachinediagramskeeptracko

8、fallstatusconditionrequirementsforoneparticularclass.Theyalsoshowthebusinessrulesthatcontrolthechangingofonestate(statuscondition)toanother.2024/7/25第7页/共53页第七页,共54页。1.2Object-OrientedDesignModelsandProcessesArchitecturaldesignisoneofthefirststepsinsystemsdesign,inasmuchasitprovidesthebigpictureando

9、verallstructureofthenewsystem.Atthetopoftherightcolumnarecomponentdiagramsanddeploymentdiagrams.wenextseedesignclassdiagrams,orDCDs,whichareanexpansionofthedomainmodelclassdiagram.Thedesignversionofsequencediagramsismuchmoredetailedandisusedtocarryoutmuchofthedetaileddesignactivity.2024/7/25第8页/共53页

10、第八页,共54页。2.Object-OrientedArchitecturalDesignInmostcases,developersbegintothinkabouthowthesystemwillbedeployedandwhattheoverallstructurewilllooklikeduringtheearlystepsofrequirementsgatheringanddocumentation.Softwaresystemsaregenerallydividedintotwotypes:1.single-usersystems2.enterprise-levelsystems.

11、2024/7/25第9页/共53页第九页,共54页。2.Object-OrientedArchitecturalDesignEnterprise-levelsystemsalmostalwaysuseclient/serverarchitectureswithmultiplelayers.Characteristicofenterprise-levelsystems,thedatabaseanddataaccessareonacentralserverbecauseitisasharedresourcethroughouttheorganization.2024/7/25第10页/共53页第十

12、页,共54页。2.Object-OrientedArchitecturalDesign2024/7/25Design IssueClient/Server Network System Internet System (Web)StateStateful” or state-based system e.g., client/server connection is long term.“Stateless systeme.g., client/server connection is not long term and has no inherent memory.Client config

13、uration Screens and forms that are programmed are displayed directly.Domain layer is often on the client or split between client and servermachines.Screens and forms aredisplayed only through abrowser. They must conform to browser technologyServerconfiguration Application or data server directly con

14、nects to client tier.Client tier connectsindirectly to the application server through a Web server第11页/共53页第十一页,共54页。2.Object-OrientedArchitecturalDesignTheconceptofstaterelatestothepermanenceoftheconnectionbetweentheclientviewlayerandtheserverdomainlayer.Iftheconnectionispermanent,asinaclient/serve

15、rsystem,valuesinvariablescanbepassedbackandforthandarerememberedbyeachcomponentinthesystem.Theviewlayerhasdirectaccesstothedatafieldsinthedomainlayer.Inastatelesssystem,suchastheInternet,theclientviewlayerdoesnthaveapermanentconnectiontotheserverdomainlayer.2024/7/25第12页/共53页第十二页,共54页。2.1ComponentDi

16、agramsandArchitecturalDesignThecomponentdiagramidentifiesthelogical,reusable,andtransportable(portable?)systemcomponentsthatdefinethesystemarchitecture.Theessentialelementofacomponentdiagramisthecomponentelementwithitsinterfaces.Acomponentisanexecutablemoduleorprogram,anditconsistsofalltheclassestha

17、tarecompiledintoasingleentity.Therearetwowaystorepresentacomponent:asageneralclassorasaspecificinstance.2024/7/25第13页/共53页第十三页,共54页。2.1ComponentDiagramsandArchitecturalDesign2024/7/25第14页/共53页第十四页,共54页。StereotypingUMLdoeshaverulesforstereotypingasymbolandforextendingthelanguage2024/7/25第15页/共53页第十五页

18、,共54页。Two-LayerArchitecturalDesignofInternetSystems2024/7/25第16页/共53页第十六页,共54页。Two-LayerArchitecturalDesignofInternetSystemsThebusinesslogicinthedomainlayerfrequentlyrelatesonlytodataformattingandtodecidingwhichdatabasetabletoupdate.DuetothestructureofWebservers,theprogram(definedasobject-orientedcl

19、asses)thatprocessestheinputformsalsooutputstheHTMLcodethatissentbacktotheclientbrowser.ThebasicideaisthatevenaWeb-basedsystemcanbedevelopedinmultiplelayersoftheviewthatis,theuserinterface,themodel(whichisthebusinesslogicanddatabaseaccess),andthecontroller(whichprovidesalinkbetweentheviewandthemodel)

20、.2024/7/25第17页/共53页第十七页,共54页。2.1ComponentDiagramsandArchitecturalDesignItiscriticallyimportantforthesamebackendbusinesslogicanddatabaseaccesstolinkwitheitheruserinterface.Consequently,thedesignteammustspecifythearchitecturaldesigninenoughdetailtoensuretheprogrammersimplementasystemthatcansupportboth

21、userinterfaces.Eachcomponentisanexecutableprogramandismadeupofclasses.2024/7/25第18页/共53页第十八页,共54页。3.FundamentalPrinciplesofObject-OrientedDetailedDesignTheobjectiveofobject-orienteddetaileddesignistoidentifyandspecifyalltheobjectsthatmustworktogethertocarryouteachusecase.Onemajorresponsibilityofdeta

22、ileddesignistoidentifyanddescribeeachsetofobjectswithineachlayerandtoidentifyanddescribetheinteractionsormessagesthataresentbetweentheseobjects.Thefullsequencediagramisusedfordesignandisatypeofinteractiondiagram.Acommunicationdiagramisalsoatypeofinteractiondiagram.2024/7/25第19页/共53页第十九页,共54页。3.Funda

23、mentalPrinciplesofObject-OrientedDetailedDesign2024/7/25第20页/共53页第二十页,共54页。3.FundamentalPrinciplesofObject-OrientedDetailedDesign2024/7/25第21页/共53页第二十一页,共54页。3.FundamentalPrinciplesofObject-OrientedDetailedDesignItdescribesthesetofobject-orientedclassesneededforprogramming,navigationbetweentheclasse

24、s,attributenamesandproperties,andmethodnamesandproperties.Adesignclassdiagramisasummaryofthefinaldesignthatwasdevelopedbyusingthedetailedsequencediagrams,anditisuseddirectlywhendevelopingtheprogrammingcode.2024/7/25第22页/共53页第二十二页,共54页。Translatemodelintocode.Thesamemodelispresentedindifferentlanguage

25、s.2024/7/25第23页/共53页第二十三页,共54页。第24页/共53页第二十四页,共54页。3.1Object-OrientedDesignProcess2024/7/25第25页/共53页第二十五页,共54页。4.DesignClassesandtheDesignClassDiagramThedomainmodelclassdiagramshowsasetofproblemdomainclassesandtheirassociations.Duringanalysis,becauseitisadiscoveryprocess,analystsgenerallydontworrymu

26、chaboutthedetailsoftheattributes.However,inOOP,theattributesofaclassmust?bedeclaredas publicorprivate,andeachattributemustalsobedefinedbyitstype,suchascharacterornumeric.Duringdetaileddesign,itisimportanttoelaborateonthesedetailsaswellastodefinethemethodsandparametersthatarepassedtothemethodsandther

27、eturnvaluesfrommethods.2024/7/25第26页/共53页第二十六页,共54页。4.1DesignClassSymbolsAstereotypeissimplyawaytocategorizeamodelelementasacertaintype.Astereotypeextendsthebasicdefinitionofamodelelementbyindicatingthatithassomespecialcharacteristicwewanttohighlight.EntityControllerBoundary2024/7/25第27页/共53页第二十七页,共

28、54页。Anentityclassisthedesignidentifierforaproblemdomainclass.Itisalsousuallyapersistentclass.Apersistentclassisonewithobjectsthatexistaftertheprogramquits.Aboundaryclass,orviewclass,isspecificallydesignedtoliveonthesystemsautomationboundary.Inadesktopsystem,theseclasseswouldbethewindowsclassesandall

29、theotherclassesassociatedwiththeuserinterface.2024/7/25第28页/共53页第二十八页,共54页。4.1DesignClassSymbolsAcontrolclassmediatesbetweentheboundaryclassesandtheentityclasses.Inotherwords,itsresponsibilityistocatchthemessagesfromtheboundaryclassobjectsandsendthemtothecorrectentityclassobjects.Itactsasakindofswit

30、chboard,orcontroller,betweentheviewlayerandthedomainlayer.Adataaccessclassisusedtoretrievedatafromandsenddatatoadatabase.Ratherthaninsertdatabaseaccesslogic,includingSQLstatements,intotheentityclassmethods,aseparatelayerofclassestoaccessthedatabaseisoftenincludedinthedesign.2024/7/25第29页/共53页第二十九页,共

31、54页。4.1DesignClassSymbols2024/7/25第30页/共53页第三十页,共54页。4.1DesignClassSymbols2024/7/25第31页/共53页第三十一页,共54页。4.2DesignClassNotationTheformatthatanalystsusetodefineeachattributeincludes:VisibilityWhetherotherobjectscandirectlyaccesstheattribute.(Aplussignindicatesthatanattributeisvisible,orpublic;aminussig

32、nindicatesthatitisntvisible,orprivate.)AttributenameType-expression(suchascharacter,string,integer,number,currency,ordate)Initial-value,ifapplicableProperty(withincurlybraces),suchaskey,ifapplicable2024/7/25第32页/共53页第三十二页,共54页。4.2DesignClassNotationRememberthatintheobject-orientedapproach,aclassisat

33、emplatetocreateindividualobjectsorinstances.Thethirdcompartmentcontainsthemethodsignatureinformation.Amethodsignatureshowsalltheinformationneededtoinvoke(orcall)themethod.Itshowstheformatofthemessagethatmustbesent,whichconsistsofthese:MethodvisibilityMethodnameMethodparameterlist(incomingarguments)R

34、eturntype-expression(thetypeofthereturnparameterfromthemethod)2024/7/25第33页/共53页第三十三页,共54页。4.2DesignClassNotation2024/7/25第34页/共53页第三十四页,共54页。4.2DesignClassNotationEachofthesubclassesalsohasauniqueattributethatisunderlined,suchasnoOfPhoneSales.Underlinedattributesareclass-levelattributesandhavethesa

35、mecharacteristicsasclass-levelmethods.Aclass-levelattributeisastaticvariable,anditcontainsthesamevalueinallinstantiatedobjectsofthesametype.Anitalicizedclassnameindicatesthatitisanabstractclassaclassthatcanneverbeinstantiated.Eachofthethreesubclassesisconsideredaconcreteclassbecauseitcanbeinstantiat

36、ed;inotherwords,objectscanbecreated.2024/7/25第35页/共53页第三十五页,共54页。4.3DevelopingtheFirst-cut(初步(chb)DesignClassDiagram2024/7/25第36页/共53页第三十六页,共54页。4.3DevelopingtheFirst-CutDesignClassDiagramThefirst-cutdesignclassdiagramisdevelopedbyextendingthedomainmodelclassdiagram.Itrequirestwosteps:(1)elaborating

37、ontheattributeswithtypeandinitialvalueinformationand(2)addingnavigationvisibilityarrows.Asindicatedearlier,object-orienteddesignisusecasedriven.2024/7/25第37页/共53页第三十七页,共54页。4.3DevelopingtheFirst-CutDesignClassDiagram2024/7/25第38页/共53页第三十八页,共54页。AttributeVisibility,NavigationandNavigationVisibilityHe

38、reareafewgeneralguidelines:One-to-manyassociationsthatindicateasuperior/subordinaterelationshipareusuallynavigatedfromthesuperiortothesubordinateforexample,fromSaletoSaleItem.Sometimes,theserelationshipsformhierarchiesofnavigationchainsforexample,fromPromotiontoProductItemtoInventoryItem.Mandatoryas

39、sociations,inwhichobjectsinoneclasscantexistwithoutobjectsofanotherclass,areusuallynavigatedfromthemoreindependentclasstothedependentclassforexample,fromCustomertoSale.Whenanobjectneedsinformationfromanotherobject,anavigationarrowmightberequired,pointingeithertotheobjectitselfortoitsparentinahierarc

40、hy.Navigationarrowsmaybebidirectional.2024/7/25第39页/共53页第三十九页,共54页。4.3DevelopingtheFirst-CutDesignClassDiagram2024/7/25第40页/共53页第四十页,共54页。4.3DevelopingtheFirst-CutDesignClassDiagramThreepointsareimportanttonote.1.First,asdetaileddesignproceedsusecasebyusecase,weneedtoensurethatthesequencediagramssup

41、portandimplementthenavigationthatwasinitiallydefined.2.Second,thenavigationarrowsneedtobeupdatedasdesignprogressestobeconsistentwiththedesigndetails.3.Finally,methodsignatureswillbeaddedtoeachclassbasedonthedesigndecisionsmadewhencreatingthesequencediagramsfortheusecases.2024/7/25第41页/共53页第四十一页,共54页

42、。5.DetailedDesignwithCRCCardsCRCcardsareabrainstormingtechniquethatisquitepopularamongobjectorienteddevelopers.Here,“CRC”isanacronymforClassResponsibilityCollaboration.2024/7/25第42页/共53页第四十二页,共54页。5.DetailedDesignwithCRCCardsForeachusecaseyouneedtodesign,thesestepsaredoneiteratively:1.Selectingausec

43、ase2.IdentifyingtheproblemdomainclassthathasresponsibilityforthisusecaseThisobjectwillreceivethefirstmessagefromtheusecasecontroller.Usingthedomainmodelthatwasdevelopedduringanalysis,selectoneclasstotakeresponsibility.Focusonlyontheproblemdomainclasses.Ontheleftsideofthecard,writetheobjectsresponsib

44、ility.3.Identifyingotherclassesthatmustcollaboratewiththeprimaryobjectclasstocompletetheusecase2024/7/25第43页/共53页第四十三页,共54页。5.DetailedDesignwithCRCCardsAttheendofthisprocess,youwillhaveasmallsetofCRCcardsthatcollaboratetosupporttheusecase.Anotherhelpfulstepistoincludetheuser-interfaceclasses.Anyothe

45、rrequiredutilityclassescanalsobeaddedtothesolution.2024/7/25第44页/共53页第四十四页,共54页。5.DetailedDesignwithCRCCards2024/7/25第45页/共53页第四十五页,共54页。6.FundamentalDetailedDesignPrinciplesCouplingCouplingisaqualitativemeasureofhowcloselytheclassesinadesignclassdiagramarelinked.Asimplewaytothinkaboutcouplingisasth

46、enumberofnavigationarrowsonthedesignclassdiagram.Lowcouplingisusuallybetterforasystemthanhighcoupling.Inotherwords,fewernavigationvisibilityarrowsindicatethatasystemiseasiertounderstandandmaintain.2024/7/25第46页/共53页第四十六页,共54页。6.FundamentalDetailedDesignPrinciplesCohesionButwhatifthatsameobjectalsoha

47、dmethodstomakeclassroomassignmentsorassignprofessorstocourses?Thecohesivenessoftheclasswouldbereduced.Classeswithlowcohesionhaveseveralnegativeeffects.First,theyarehardtomaintain.Second,itishardtoreusesuchclasses.2024/7/25第47页/共53页第四十七页,共54页。6.FundamentalDetailedDesignPrinciplesProtectionfromvariati

48、onsOneoftheunderlyingprinciplesofgooddesignisprotectionfromvariationstheideathatthepartsofasystemthatareunlikelytochangeshouldbesegregated(orprotected)fromthosethatwillchange.Protectionfromvariationsisaprinciplethatdrivesthemultilayerdesignpattern.2024/7/25第48页/共53页第四十八页,共54页。6.FundamentalDetailedDe

49、signPrinciplesIndirectionIndirectionistheprincipleofdecouplingtwoclassesorothersystemcomponentsbyplacinganintermediateclassbetweenthemtoserveasalink.Inotherwords,instructionsdontgodirectlyfromAtoB;theyaresentthroughCfirst.Orinmessageterminology,dontsendamessagefromAtoB;letAsendthemessagetoCandthenle

50、tCforwardittoB.Insertinganintermediateobjectallowsanyvariationsinonesystemtobeisolatedinthatintermediateobject.Indirectionisalsousefulformanycorporatesecuritysystems.2024/7/25第49页/共53页第四十九页,共54页。ObjectResponsibilityOneofthemostfundamentalprinciplesofobject-orienteddevelopmentistheideaofobjectrespons

51、ibility;thatis,objectsareresponsibleforcarryingoutthesystemprocessing.Theseresponsibilitiesarecategorizedintwomajorareas:1.KnowingWhatisanobjectexpectedtoknow?2.Doing.Whatisanobjectexpectedtodoortoinitiate?2024/7/25第50页/共53页第五十页,共54页。ObjectResponsibility:Knowning“Knowing”includesanobjectsresponsibil

52、itiesforknowingaboutitsowndataandknowingaboutotherclasseswithwhichitmustcollaboratetocarryoutusecases.Obviously,aclassshouldknowaboutitsowndata,whatattributesexist,andhowtomaintaintheinformationinthoseattributes.Anobjectshouldknowaboutorhavenavigationvisibilitytootherobjectsthatcanprovidetherequired

53、information.2024/7/25第51页/共53页第五十一页,共54页。ObjectResponsibility:Doing“Doing”includesalltheactivitiesanobjectdoestoassistinexecutingausecase.Someofthoseactivitiesincludereceivingandprocessingmessages.Anotheractivityistoinstantiate,orcreate,newobjectsthatmayberequiredforcompletionofausecase.Classesmustc

54、ollaboratetocarryoutausecase,andsomeclassesareresponsibleforcoordinatingthecollaboration.2024/7/25第52页/共53页第五十二页,共54页。2024/7/25感谢您的欣赏(xnshng)!第53页/共53页第五十三页,共54页。内容(nirng)总结1. Object-Oriented Design: Bridging from Analysis to Implementation。“Stateless systeme.g.,。Initial-value, if applicable。感谢您的欣赏(xnshng)第五十四页,共54页。

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 研究生课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号