| Introduction to OOP | Chapter 23: Object Interconnections : | next | previous | audio | real | text |
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;
@end
|
@implementation GraphicalReactor : Reactor
- (void) setHeat: (double) newValue
{
/* code necessary to */
/* update gauge */
[ super setHeat: newValue ];
}
@end
|