3 ms·
> Seems almost identical to defining a record and module of functions that operate on said record. OO is mostly that plus the ability to forbid people from usi
by jtolmar 9y ago
> Seems almost identical to defining a record and module of functions that operate on said record.
OO is mostly that plus the ability to forbid people from using the record without using the functions.
> by attaching the functions you create new copies of each function with a bound reference to the instance of data structure.
Yes, but the compiler won't actually copy the function, it'll implement it as something closer to the record plus modules approach (for example a record plus a pointer to the module). This might not be true if you're trying to use OO in a functional language.
- zumu 9y agoThanks for taking the time to give these detailed responses. One more question (restated from below): Coming from FP where immutability is sacrosanct, I often wind up writing classes that are largely immutable, which doesn't seem like correct OOP. Is there a proper way to marry immutable data structures with OO?
- jtolmar 9y agoThe object-oriented world has been moving towards more immutable and mostly-immutable classes. This is sometimes awkward with large classes, so people use the builder pattern to get around it. (It's a case of languages having not caught up with practices.)