Re:Pretending OOP Never Happened
by beeforpork on Friday May 15, 2020 @01:36PM
(#23194912)
How is there a smaller set because of OOP? Just filter the functions by parameter type to restrict which function may access your pointer.
[ Parent
| on HN ]
OOP encourages modifying an object's state via its member functions (if you use data hiding/encapsulation as part of your OOP definition). This means that users of class instances shouldn't be able to put it into a bad state, unless the member functions are able to put it in a bad state.
This lets you isolate where your contract/invariant violations are more easily. Once addressed in the member functions, either it fixes it in the callers, or their use is now invalid and becomes a compile or runtime error.