Unformatted text preview:

VisibilityWhat is visibility?What does the getProductDesc message imply about object visibility?Four Kinds of VisibilityAttribute VisibilityParameter VisibilityGlobal VisibilitySingleton design pattern Gamma, Helm, Johnson, and Vlissides (aka Gang of Four)Questions for discussionVisibilityVisibilityLarman, Chapter 19Larman, Chapter 19(with ideas from George Blank of (with ideas from George Blank of NJIT)NJIT)CSE432CSE432Object Oriented Software Object Oriented Software EngineeringEngineeringWhat is visibility?What is visibility?VisibilityVisibility is the ability of one object to “see” is the ability of one object to “see” or have reference to anotheror have reference to anotherTo send a message from one object to To send a message from one object to another, the receiver object must be another, the receiver object must be “visible” to the sender, via a reference“visible” to the sender, via a referenceWhat does the getProductDesc What does the getProductDesc message imply about object visibility?message imply about object visibility?: RegisterenterItem(itemID, quantity): ProductCatalogdesc = getProductDesc( itemID )public void enterItem( itemID, qty ){ ... desc = catalog.getProductDesc(itemID) ...}class Register{ ... private ProductCatalog catalog; ...}Fig. 19.1Four Kinds of VisibilityFour Kinds of VisibilityOO programming languages may OO programming languages may provide four levels of scope for provide four levels of scope for names:names:Attribute visibilityAttribute visibilityParameter visibilityParameter visibilityLocal visibilityLocal visibilityGlobal visibilityGlobal visibilityAttribute VisibilityAttribute VisibilityFig. 19.2Parameter VisibilityParameter VisibilityFig. 19.3 Why is transforming parameters to attribute visibility Why is transforming parameters to attribute visibility common in OO design? common in OO design?Global VisibilityGlobal VisibilityObject B has global scope relative to Object B has global scope relative to AARelatively permanent visibilityRelatively permanent visibilityLeast common visibility in OO designLeast common visibility in OO designWays to achieve global visibility:Ways to achieve global visibility:Assign an instance to a global variable.Assign an instance to a global variable.Use the Singleton patternUse the Singleton patternSingleton design patternSingleton design patternGamma, Helm, Johnson, and Vlissides (aka Gang of Gamma, Helm, Johnson, and Vlissides (aka Gang of Four)Four)Ensure that a class has only one instance and Ensure that a class has only one instance and provide provide a global point of access to ita global point of access to itWhy not use a global variable?Why not use a global variable?class Singleton class Singleton { public: { public: static Singleton* getInstance(); //accessorstatic Singleton* getInstance(); //accessor protected: //protected: //Why are the following protected?Why are the following protected? Singleton(); Singleton(); Singleton(const Singleton&); Singleton(const Singleton&); Singleton& operator= (const Singleton&); Singleton& operator= (const Singleton&); private: static Singleton* instance; //uniqueprivate: static Singleton* instance; //unique }; }; Singleton *p2 = p1->getInstance();Singleton *p2 = p1->getInstance();Questions for discussion Questions for discussion Q. Which would you use if you wanted a Q. Which would you use if you wanted a relatively permanent connection relatively permanent connection between sender & receiver objects? between sender & receiver objects? A. attribute, or global A. attribute, or global Q. Q. Which would you use if you didn't want a Which would you use if you didn't want a permanent connection? permanent connection? A.A.parameter, or local parameter, or local Q. Q. How would you achieve global visibility? How would you achieve global visibility? A.A.use a global variable in C++, use a global variable in C++, static (or class) variable (in C++ or Java) static (or class) variable (in C++ or Java) or the Singleton pattern (a static or the Singleton pattern (a static method that returns the object) method that returns the


View Full Document

LEHIGH CSE 432 - Visibility

Download Visibility
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Visibility and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Visibility 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?