3 ms·
OOP had another advantage over procedural: Often in procedural programming, you'd pass around a pointer to some data structure. If the data structure got mess
by AnimalMuppet 7y ago
OOP had another advantage over procedural: Often in procedural programming, you'd pass around a pointer to some data structure. If the data structure got messed up (put in an inconsistent state, say), you had no idea what code was responsible. With OOP, you look at the class's member functions, which is a much smaller set.
- zozbot234 7y ago> If the data structure got messed up (put in an inconsistent state, say), you had no idea what code was responsible. With OOP, you look at the class's member functions, which is a much smaller set. Yes this is correct. But data abstraction and encapsulation are found in all object-based code; they're not specific or related to OOP.
- AnimalMuppet 7y agoI'm not sure I understand. In your view, what is the difference between "object-based code" and OOP?
- kingdomcome50 7y agoSimply using objects in the code doesn't mean one is practicing OOP any more than using functions means one is practicing FP. That is, it is more about the "how" than the "what".
- beeforpork 7y agoHow is there a smaller set because of OOP? Just filter the functions by parameter type to restrict which function may access your pointer.
- Jtsummers 7y agoOOP 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.
- Konohamaru 7y agoIt seems like there is a whole subject buried in this comment.