Answer the question
In order to leave comments, you need to log in
Which one of us is right about Encapsulation in OOP?
Arguing with a friend about encapsulation.
I argue that the essence of encapsulation is access control. Explaining that the keywords PUBLIC, PROTECTED and PRIVATE are its foundation.
A friend claims that:
Encapsulation is, first of all, the combination of data (variables) and methods (functions) of processing them in an object. The function code is hidden from the user (The user does not know how this function works, he only receives the result).
ps Your decision on the dispute is interesting. It is who is right and who is not. Thank you.
Answer the question
In order to leave comments, you need to log in
Your friend describes the meaning of encapsulation, and you are the means to implement it. In my opinion, your friend interprets in a more general sense, more fully.
Of the books that treat encapsulation -
Interpretation #1
Encapsulation is the combination of data and the functions that manage that data into a single component.
Interpretation No. 2
Encapsulation is a mechanism of a separate taken language, which allows you to restrict the access of some program components to others.
Encapsulation provides hiding, but is not hiding.
If it’s more simple -
Encapsulation - we hide the complexity inside , and expose several simple interfaces outside (the principle of a TV is we have a remote control, and all the “wires” are hidden in the case).
Understanding encapsulation only as hiding is not entirely correct.
Data hiding can be achieved, for example, in C. Which is not a language with an OOP paradigm at all.
So the connection of functions and data is a more correct definition. Plus, definitions differ from language to language, and from book to book. The creator of OOP (Alan Kay) generally understood OOP in a completely different way from how it is implemented in my cozy Java, for example. And nothing. :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question