meeting -*- Outline -*- * Design Model: Determining Visibility (Larman Ch. 18) ** visability between objects (18.1) definition: visibility is the ability of one object to see or have a reference to another object. Q: When is visibility necessary? To send a message from one object to another, the receiver object must be visible to the sender, so the sender has to have a pointer or reference to the receiver. Q: So if a Register sends messages to a ProductCatalog, which must be visible to which? So B is visible to A means A can send a message to B. Some say that "B is an acquaintence of A". ** Visibility (18.2) ------------------------------------------ KINDS OF VISIBILITY Object B is visible to A if: - attribute visibility - parameter visibility - local visibility - global visibility ------------------------------------------ ... B is an attribute of A e.g., ProductCatalog is attribute of Register ... B is a parameter of a method of A e.g., a ProductSpecification is passed to Sale in MakeLineItem ... B is a local object in A (but not a parameter) e.g., in ProductCatalog's getSpecification method, a ProductSpecification is locally visible ... B is globally visible (e.g., in a global variable) Q: Which would you use if you wanted a relatively permanent connection? attribute, or global Q: which would you use if you didn't want a permanent connection? parameter, or local Q: how would you create a local visibility? - create a new instance - use result of a method call Q: how would you achieve a global visibility? - use a global variable in C++, static (or class) variable (in C++ or Java) - use the Singleton pattern (a static method that returns the object)