3 ms·
I also think that asking the user to allocate memory is bad (for OOP) design, because it is leaking information which should be encapsulated into the class. How
by angersock 12y ago
I also think that asking the user to allocate memory is bad (for OOP) design, because it is leaking information which should be encapsulated into the class. How does the user even know how, or what to allocate in order to work with your "methods"?
What? Gods no!
The user knows more about their runtime environment than your objects--indeed, consider this a form of DI for memory management.
Libraries that don't let me override allocations, file access, and logging are very, very bad.
- sparkie 12y agoIn that case you would inject a function pointer to an allocator (and deallocator), however, the object constructor is the only thing which knows how to allocate the object - consider the jagged array example I gave, or even a linked list - the user has no idea how they're allocated if given just an opaque pointer.