您好,欢迎访问三七文档
SchoolofSoftwareNanchangUniversitySchoolofSoftwareNanchangUniversity©NanchangUniversity,Spring2014DesigningforVisibilityOOAD-DesignModelSchoolofSoftwareNanchangUniversityObjectivesIdentifyfourkindsofvisibilityDesigntoestablishvisibilityIllustratekindsofvisibilityintheUMLnotationSchoolofSoftwareNanchangUniversityIntroductionQ.Whatisvisibility?A.Visibilityistheabilityofoneobjecttoseeorhavereferencetoanother.SchoolofSoftwareNanchangUniversityVisibilityBetweenObjectsQ.Whenisvisibilitynecessary?A.Tosendamessagefromoneobjecttoanother,thereceiverobjectmustbevisibletothesender,sothesenderhastohaveapointerorreferencetothereceiver.SchoolofSoftwareNanchangUniversityVisibilityBetweenObjectsExample:Q.IfAsendsmessagestoB,whichmustbevisibletowhich?A.BisvisibletoAmeansAcansendamessagetoB.SomesaythatBisanacquaintanceofA.SchoolofSoftwareNanchangUniversityVisibilityBetweenObjectsSchoolofSoftwareNanchangUniversityVisibilityVisibilityisrelatedtothescope:Isoneresource(suchasaninstance)withinthescopeofanother?Themotivationtoconsidervisibility:ForanobjectAtosendamessagetoanobjectB,BmustbevisibletoA.SchoolofSoftwareNanchangUniversityFourKindsofVisibilityHowvisibilitycanbeachievedfromobjectAtoobjectB:Attributevisibility-BisanattributeofAParametervisibility-BisaparameterofamethodofALocalvisibility-BisalocalobjectinamethodofAGlobalvisibility-BisinsomewaygloballyvisibleSchoolofSoftwareNanchangUniversityAttributeVisibilityAttributevisibilityfromAtoBexistswhenBisanattributeofARelativelypermanentvisibilitybecauseitpersistsaslongasAandBexistCommonformofvisibilitypublicclassRegister{…privateProductCatalogCatalog;…}SchoolofSoftwareNanchangUniversityAttributeVisibilitySchoolofSoftwareNanchangUniversityParameterVisibilityParametervisibilityfromAtoBexistswhenBispassedasaparametertoamethodofA.RelativelytemporaryvisibilitybecauseitpersistsonlywithinthescopeofthemethodThe2ndmostcommonformofvisibilityintheOOsystemsSchoolofSoftwareNanchangUniversityParameterVisibilitySchoolofSoftwareNanchangUniversityParametertoattributeVisibilityItiscommontotransformparametervisibilityintoattributevisibility.SchoolofSoftwareNanchangUniversityLocalVisibilityLocalvisibilityfromAtoBexistswhenBisdeclaredasalocalobjectwithinamethodofA.Relativelytemporaryvisibilitysinceitpersistsonlywithinthescopeofthemethod.SchoolofSoftwareNanchangUniversityLocalVisibilityTherearetwocommonmeansbywhichlocalvisibilityisachieved:Createanewlocalinstanceandassignittoalocalvariable.Assignthereturningobjectfromamethodinvocationtoalocalvariable.Avariationofthismethoddoesnotexplicitlydeclareavariable,butoneimplicitlyexistsastheresultofareturningobjectfromamethodinvocationExample:anObject.getAnotherObject.doSomething();SchoolofSoftwareNanchangUniversityGlobalVisibilityGlobalvisibilityfromAtoBexistswhenBisglobaltoA.RelativelypermanentvisibilitysinceitpersistsaslongasAandBexist.TheleastcommonformofvisibilityinOOSystems.Waystoachieveglobalvisibility:Assignaninstancetoaglobalvariable.UsetheSingletonpatternSchoolofSoftwareNanchangUniversitySingletonPattern(GangofFour)Problem:Exactlyoneinstanceofaclassisneeded.Objectsneedasinglepointofaccess.Solution:Defineaclassmethodthatreturnsthesingletonobject,instantiatingitifitdoesnotexist.Example:Aprintqueue—manyprogramsmustaccessonequeueSchoolofSoftwareNanchangUniversityIllustratingVisibilityintheUMLSchoolofSoftwareNanchangUniversityVisibilityintheUMLPublic:Anyoutsideclassifierwithvisibilitytothegivenclassifiercanusethefeature;specifiedbypre-pendingthesymbol“+”Protected:Anydescendantoftheclassifiercanusethefeature;specifiedbypre-pendingthesymbol“#”Private:Onlytheclassifieritselfcanusethefeature;specifiedbypre-pendingthesymbol“-”SchoolofSoftwareNanchangUniversityTerms:ClassifierAClassifiersisamechanismthatdescribesstructuralandbehavioralfeatures.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)
本文标题:12.OOAD
链接地址:https://www.777doc.com/doc-3800097 .html