Introduction to OOP Chapter 23: Object Interconnections : next previous audio real text

Active Values

The creation of active values is a good illustration of why parameter coupling is better than direct manipulation.

Suppose we have an existing program and we just want to observe a data value - see when it gets set and changed.

Solution - create a new subclass that just changes those methods that set or read the data value.

@interface Reactor : Object
{ ...
	double heat; ...
- (void)  setHeat: (double) newValue;	
- (double) getHeat;

@implementation GraphicalReactor : Reactor
- (void) setHeat: (double) newValue
		/* code necessary to */ 
		/* update gauge */
		[ super setHeat: newValue ];

Can add new functionality simply by replacing an object with an instance of a subclass; making no change to the original class.

Intro OOP, Chapter 23, Slide 18