Added by Johan Stuyts, last edited by Johan Stuyts on Sep 12, 2006  (view change)

Labels:

Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.

External Monitor Object - Structural

Full text

Intent

Sometimes it is needed to monitor what is going on inside an object. But objects should not expose implementation details because this prohibits changes to the implementation. By using an External Monitor Object other objects can look inside an object, while still allowing the implementation of that object to change in the future without requiring client code changes and/or recompilation.

Motivation

For performance monitoring and other reasons it may be needed to be able to peek inside an object so information can be gathered and analyzed. The information that can be gathered often depends on the implementation of an object. If the object would give direct access to the information by adding additional methods to its interface, client code will become dependent on those methods. This makes it impossible to switch to another implementation because clients expect the information methods to continue to return correct results.

By using an External Monitor Object clients no longer gather information from the object directly. The client can obtain the External Monitor Object through an additional gettermethod of the monitored object. To prevent coupling of the monitered object and the External Monitor Object, the return type of the getter method must be Objectinstead of the type of the External Monitor Object. Because the return type is Objectclients that want to gather information have to check that the returned External Monitor Object is of the type that they expect. This type check makes it possible to change the implementation of the monitored object, and the type of the External Monitor Object without breaking existing clients.

Implementations

No reusable implementations of this solution are available because each object needs unique monitor objects.

It is possible to define standard monitor interfaces for objects having a (similar) implementation so information gathering clients can be reused. There are no such interfaces yet.