1 / 9

Visibility

Visibility. Larman, Chapter 19 (with ideas from George Blank of NJIT) CSE432 Object Oriented Software Engineering. What is visibility?. Visibility is the ability of one object to “see” or have reference to another

glennis
Télécharger la présentation

Visibility

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visibility Larman, Chapter 19 (with ideas from George Blank of NJIT) CSE432 Object Oriented Software Engineering

  2. What is visibility? • Visibility is the ability of one object to “see” or have reference to another • To send a message from one object to another, the receiver object must be “visible” to the sender, via a reference

  3. What does the getProductDesc message imply about object visibility? Fig. 19.1

  4. Four Kinds of Visibility OO programming languages may provide four levels of scope for names: • Attribute visibility • Parameter visibility • Local visibility • Global visibility

  5. Attribute Visibility Fig. 19.2

  6. Parameter Visibility Fig. 19.3 • Why is transforming parameters to attribute visibility common in OO design?

  7. Global Visibility • Object B has global scope relative to A • Relatively permanent visibility • Least common visibility in OO design • Ways to achieve global visibility: • Assign an instance to a global variable. • Use the Singleton pattern

  8. Singleton design patternGamma, Helm, Johnson, and Vlissides (aka Gang of Four) • Ensure that a class has only one instance and provide a global point of access to it • Why not use a global variable? class Singleton { public: static Singleton* getInstance(); //accessor protected: //Why are the following protected? Singleton(); Singleton(const Singleton&); Singleton& operator= (const Singleton&); private: static Singleton* instance; //unique }; Singleton *p2 = p1->getInstance();

  9. Questions for discussion Q. Which would you use if you wanted a relatively permanent connection between sender & receiver objects? A. attribute, or global Q. Which would you use if you didn't want a permanent connection? A. parameter, or local Q. How would you achieve global visibility? A. use a global variable in C++, static (or class) variable (in C++ or Java) or the Singleton pattern (a static method that returns the object)

More Related