in reply to Re^13: Assignable Subroutines
in thread Assignable Subroutines
or$employee->setSalary(50000);
$employee->Salary = 50000;
The whole problem here comes originally from people exposing highly interrelated fields as independently manipulable things when they shouldn't and in that case mutators are wrong. The whole idea is to be able to have invariants that are always true about an object and giving access to individual fields can sometimes allow things outside the object to leave the object in a state where the invariant is no longer true. I totally appreciate that. But sometimes objects have fields that are independent of all other fields and can be twiddled by anyone without breaking an invariant. There are only 2 choices for implementing these - direct field access or mutator and in most languages direct access is bad because it cannot be overridden in the future so you use a mutator.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^15: Assignable Subroutines
by dragonchild (Archbishop) on Jan 27, 2005 at 19:58 UTC | |
by fergal (Chaplain) on Jan 27, 2005 at 20:53 UTC |