12.OOAD

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

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

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

资源描述

SchoolofSoftwareNanchangUniversitySchoolofSoftwareNanchangUniversity©NanchangUniversity,Spring2014DesigningforVisibilityOOAD-DesignModelSchoolofSoftwareNanchangUniversityObjectivesIdentifyfourkindsofvisibilityDesigntoestablishvisibilityIllustratekindsofvisibilityintheUMLnotationSchoolofSoftwareNanchangUniversityIntroductionQ.Whatisvisibility?A.Visibilityistheabilityofoneobjecttoseeorhavereferencetoanother.SchoolofSoftwareNanchangUniversityVisibilityBetweenObjectsQ.Whenisvisibilitynecessary?A.Tosendamessagefromoneobjecttoanother,thereceiverobjectmustbevisibletothesender,sothesenderhastohaveapointerorreferencetothereceiver.SchoolofSoftwareNanchangUniversityVisibilityBetweenObjectsExample:Q.IfAsendsmessagestoB,whichmustbevisibletowhich?A.BisvisibletoAmeansAcansendamessagetoB.SomesaythatBisanacquaintanceofA.SchoolofSoftwareNanchangUniversityVisibilityBetweenObjectsSchoolofSoftwareNanchangUniversityVisibilityVisibilityisrelatedtothescope:Isoneresource(suchasaninstance)withinthescopeofanother?Themotivationtoconsidervisibility:ForanobjectAtosendamessagetoanobjectB,BmustbevisibletoA.SchoolofSoftwareNanchangUniversityFourKindsofVisibilityHowvisibilitycanbeachievedfromobjectAtoobjectB:Attributevisibility-BisanattributeofAParametervisibility-BisaparameterofamethodofALocalvisibility-BisalocalobjectinamethodofAGlobalvisibility-BisinsomewaygloballyvisibleSchoolofSoftwareNanchangUniversityAttributeVisibilityAttributevisibilityfromAtoBexistswhenBisanattributeofARelativelypermanentvisibilitybecauseitpersistsaslongasAandBexistCommonformofvisibilitypublicclassRegister{…privateProductCatalogCatalog;…}SchoolofSoftwareNanchangUniversityAttributeVisibilitySchoolofSoftwareNanchangUniversityParameterVisibilityParametervisibilityfromAtoBexistswhenBispassedasaparametertoamethodofA.RelativelytemporaryvisibilitybecauseitpersistsonlywithinthescopeofthemethodThe2ndmostcommonformofvisibilityintheOOsystemsSchoolofSoftwareNanchangUniversityParameterVisibilitySchoolofSoftwareNanchangUniversityParametertoattributeVisibilityItiscommontotransformparametervisibilityintoattributevisibility.SchoolofSoftwareNanchangUniversityLocalVisibilityLocalvisibilityfromAtoBexistswhenBisdeclaredasalocalobjectwithinamethodofA.Relativelytemporaryvisibilitysinceitpersistsonlywithinthescopeofthemethod.SchoolofSoftwareNanchangUniversityLocalVisibilityTherearetwocommonmeansbywhichlocalvisibilityisachieved:Createanewlocalinstanceandassignittoalocalvariable.Assignthereturningobjectfromamethodinvocationtoalocalvariable.Avariationofthismethoddoesnotexplicitlydeclareavariable,butoneimplicitlyexistsastheresultofareturningobjectfromamethodinvocationExample:anObject.getAnotherObject.doSomething();SchoolofSoftwareNanchangUniversityGlobalVisibilityGlobalvisibilityfromAtoBexistswhenBisglobaltoA.RelativelypermanentvisibilitysinceitpersistsaslongasAandBexist.TheleastcommonformofvisibilityinOOSystems.Waystoachieveglobalvisibility:Assignaninstancetoaglobalvariable.UsetheSingletonpatternSchoolofSoftwareNanchangUniversitySingletonPattern(GangofFour)Problem:Exactlyoneinstanceofaclassisneeded.Objectsneedasinglepointofaccess.Solution:Defineaclassmethodthatreturnsthesingletonobject,instantiatingitifitdoesnotexist.Example:Aprintqueue—manyprogramsmustaccessonequeueSchoolofSoftwareNanchangUniversityIllustratingVisibilityintheUMLSchoolofSoftwareNanchangUniversityVisibilityintheUMLPublic:Anyoutsideclassifierwithvisibilitytothegivenclassifiercanusethefeature;specifiedbypre-pendingthesymbol“+”Protected:Anydescendantoftheclassifiercanusethefeature;specifiedbypre-pendingthesymbol“#”Private:Onlytheclassifieritselfcanusethefeature;specifiedbypre-pendingthesymbol“-”SchoolofSoftwareNanchangUniversityTerms:ClassifierAClassifiersisamechanismthatdescribesstructuralandbehavioralfeatures.Modelingelementsthatcanhaveinstancesarecalledclassifiers.Classifiersincludeclasses,interfaces,datatypes,signals,components,nodes,usecases,andsubsystems.Aclassifierhasstructuralfeature(intheformofattributes),aswellasbehavioralfeatures(intheformofoperations).SchoolofSoftwareNanchangUniversityTerms:FeatureAfeatureisaproperty,suchasoperationsorattributesthatisencapsulatedwithinentitysuchasaninterface,aclass,oradatatype.SchoolofSoftwareNanchangUniversityQuestions&AnswersQ.Whichwouldyouuseifyouwantedarelativelypermanentconnection?A.attribute,orglobalQ.Whichwouldyouuseifyoudidn'twantapermanentconnection?A.parameter,orlocalQ.Howwouldyoucreatealocalvisibility?A.createanewinstance-useresultofamethodcallSchoolofSoftwareNanchangUniversityQuestions&AnswersQ.howwouldyouachieveaglobalvisibility?A.useaglobalvariableinC++,static(orclass)variable(inC++orJava)-usetheSingletonpattern(astaticmethodthatreturnstheobject)

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

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

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

×
保存成功