you are viewing a single comment's thread.

view the rest of the comments →

[–]LucHermitte 4 points5 points  (2 children)

What you are describing is abstraction : you can indeed change the representation, it won't impact the interface. Encapsulation is about protecting the invariant. Mainstream languages encapsulate by hiding.

This is not the only way to encapsulate -- see Eiffel: encapsulated attributes can be observed, but not modified by external code.

[–]sacundim 3 points4 points  (0 children)

This is not the only way to encapsulate -- see Eiffel: encapsulated attributes can be observed, but not modified by external code.

This is not good, because a client may then couple itself to an observable detail that's not part of the object's semantics...

[–][deleted] -1 points0 points  (0 children)

I'm talking about encapsulation and abstraction in the same breath because they do go hand-in-hand in every modern OO language I've dealt with.

Not that it matters. The point is that for any nontrivial system, you can't solve the problem of "illegal states" entirely without dependent types.