Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Information hiding (encapsulation) is a good thing since it reduces the possibility of clients using "undocumented" information.</p> <p>The whole point of encapsulation is to minimise the interface to your code so that you can change the non-published bits whenever you want without affecting clients of it.</p> <p>For example, let's say you have a dictionary class which maps one string to another. Let's further say that you implemented this as a quick and dirty two-array solution because you were behind schedule - apparently this happens sometimes :-) And that you didn't encapsulate the array and methods that use it.</p> <p>So, it's been in the field for a while and millions of customers have bought it. Half of them are complaining about the speed since their dictionaries have a hundred thousand entries.</p> <p>The other half are using it by going behind your back and directly using your internal, but unhidden data structures.</p> <p>What do you do? If you do nothing, half a million of your customers will not renew their contracts and they will bad-mouth your product.</p> <p>If you change your code to use a balanced tree or hashing, the <em>other</em> half million customers will moan about your decision.</p> <p>Here's what you end up doing. You end up maintaining <em>two</em> versions, one for the large-data people, the other for the sneaky people. This increases your costs and effort considerably.</p> <p>If you had properly encapsulated your data and methods, you could have replaced the internals wholesale with absolutely no impact on any of your customers.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload