2 ms·
If one class is free to use the internals of another, it's free to tightly couple itself to another class, regardless of the abstractions involved. If one clas
by chongli 13y ago
If one class is free to use the internals of another, it's free to tightly couple itself to another class, regardless of the abstractions involved.
If one class is free to use the internals of another then it is not a sound abstraction by definition.
I see where you're coming from though, and I think decoupling is a combination of abstraction and encapsulation, not one or the other exclusively.
Your view of abstraction is too limited. Abstraction need not involve classes or objects at all. Abstractions may also be built with modules/namespaces, parametric polymorphism (aka generics) and other forms of ad-hoc polymorphism (such as type classes). All that is required to achieve abstraction is a function or data type which hides its implementation details in a way that allows it to be interchanged freely with other functions or data types that match its interface. Encapsulation is only one way to achieve such hiding.
- Jormundir 13y agoWell then likewise, your idea of encapsulation is too limited. > If one class is free to use the internals of another then it is not a sound abstraction by definition. So abstraction is not sound without encapsulation.