LARMAN CD MODULES

Module 12

Achieving Visibility

Introduction

The purpose of this CD Module is to discuss the four ways of achieving visibility between different objects. Without this visibility, a sending object would have no way to send a message to a receiving object.

What is visibility and how do we achieve it?

A sender must have visibility to the receiver in order to send the receiver a message. Once visibility is established, it creates a link, or a pathway, of visibility along which messages flow. Consider the following diagram:

However, visibility is not achieved automatically. We must explicitly establish the pathway of visibility. There are four common types of visibility:

- attribute visibility
- parameter visibility
- local visibility
- global visibility

Attribute Visibility:

We can achieve attribute visibility by declaring the receiving object as an attribute of the sender. For example, in the following diagram, we are declaring a private attribute of "ProductCatalog" which gives us visibility to a ProductCatalog object. With this visibility established, we can now send messages to ProductCatalog and get it to do some work for us, e.g."Hey, Product Catalog! Get me a product specification!".

Parameter Visibility:

Alternatively, you can achieving visibility by passing in a parameter to the receiving object. Notice in the following diagram that once the "product specification" has been obtained, it is being passed to the "Sale" object as a parameter, along with the quantity. Note that parameter visibility is a temporary visibility and goes away when we leave the scope of the method.

Local Visibility:

We can achieve local visibility by the assignment of a returning object. Note that local visibility is a temporary visibility and goes away when we leave the scope of the method.

Global Visibility:

The final form of visibility is global visibility. This provides a permanent visibility to an object. Note that in java we are unable to declare global variables, however, we can achieve global visibility through the use of a "Singleton" pattern.

Home

Module 1 | Module 5 | Module 6 | Module 7 | Module 8 | Module 9

Module 10 | Module 12 | Module 13 | Module 14