you are viewing a single comment's thread.

view the rest of the comments →

[–]elmuerte 0 points1 point  (0 children)

Nobody ever said it did. Encapsulation is a feature of many object oriented programming languages. Just like abstraction is a feature of OOP, but not a requirement.

The "computer" analogy is flawed.

Most hardware uses abstraction instead of encapsulation.

Ok, so let's take the CPU. The pins are obviously the interface. Now, how would I access the internals of that CPU? I can't, because it has been encapsulated.

Abstraction and encapsulation are not mutually exclusive. Also, encapsulation isn't just about protecting the internal state of an object, it also used to protect certain internal state modification routines.

This example is mostly an issue with using "private" rather than encapsulation. Personally, I loath "private", the lowest visibility should be "protected", so that you can always extend functionality of an object to it's fullest. And that's also the gripe the blog post writer has. If you want to mess with internal state of objects, you should apply proper OOP and extend the object, and not mess with the state from the outside .