+ 1
Why do we use encapsulation????...
encapsulation
3 Answers
+ 2
To hide some data from the user so that the user can see the codes function....not how it works....I guess
+ 1
encapsulation is one main part of object oriented programming.This pare enforce a programmer to hide its implementation into objects with a public interface.Client programmer can use only this object interface withou knowledge of the object implementation.
0
To allow for changing parts of the program without breaking others. That's the general idea. When a client calls a method on another object, they can be sure about the return type, but not what's actually happening inside.
Say, a client calls .size() on a list. There are different ways to implement that depending. If the list can change, you have to recount every time. If the size is fixed, you only have to count once and store the result.
Other way round, say, there are mutable and immutable lists. If you now have function in another part of the program, you can just use list as a parameter. You don't care what kind of list. Any will do.
So now the rest of the program can change. The function will still work.