Is it used in other programming paradigms as well? What would be a good example of when and when not to use it?
1 Answers
Oh, this is a very broad topic and it differs very much from the language/environment in wich you are working.
For example python doesn't really spend much thought about encapsulation: Why are Python's 'private' methods not actually private?
The "best" example for encapsulation would be pimpl from c++: How do you do "true" encapsulation in C++?
Encapsulation only makes real sense, when you want someone to not mess around with your inner variables.
If you got full source accesss to such things, you can always have a look, change things ( for the better or the worse ).
So, lets say, you are a software developer for the navigational system of a car. The manufacturer gave you an api-doc how to connect to the car, you can access informations via functions ( eg, get gps coordinates ) and can set informations yourself via functions. But the software handling the engine, is most likely hidden/locked for your navigation software ( well, in most cases its done badly... but just for example reasons) A good example would be the horse-power variable ( dunno if it exists ), you shoulnt be able to see/set/get that number in your navigation software... and thats all the fuss is about.