struct.With C, you can .. struct { char fname[8]; char lname[16]; int age; } student;With Java, you canpublic class record{ public String fname; public String lname; public int age;}
RE: 1.why do we need encapsulation?2. what is a ...
This answer still didnt answer why do we need encapsulation. Well from wht I know we need encapsulation to ensure the data access is secure. We can control which are the variables of hte class which can be accessed and modified by the functions outside of the class and which are the variables which are private to the class.
RE: 1.why do we need encapsulation?2. what is a ...
Analogue of C++ class in C:
We can have object-oriented implementation in C, by having a global function which implements all the interfaces of an object.The particular function will use local data-structures and locally declared functions, which will be accessible only inside the gobal function not outside it.
The locally declared functions can be get-set methods or any sort of manipulation of the locally defined data-structure.
The global function itself acts like the class.
The object creation and manipulation will be handled by this function alone.
RE: 1.why do we need encapsulation?2. what is a ...
We need encapsulation to minimize the cost of maintaining the code. When we hide the internal structure of an object, we force other objects to talk to it through a specific API. This is contract based programming. Now we can test just this object (API inputs and inspect outputs) independently of other classes. We can also make changes to this class without affecting other parts of the software - because the changes are encapsulated to the single class.Also makes it easier for multiple people to work on the same project in parallel.
RE: 1.why do we need encapsulation?2. what is a ...
In order to bind the data and functions working on it and to safegaurd our data and funtcions from outside access (access from the other objects) we need Encaptulations.
RE: 1.why do we need encapsulation?2. what is a ...
WELL DESIGNED MODULES ALWAYS HIDES ALL OF ITS IMPLEMENTAIONS DETAILS. MODULES THEN COMMUNICATE WITH EACH OTHER ONLY THROUGH API's UNKNOW TO EACH OTHER INNER IMPLEMENTATIONS
PROPER USE OF ACCESS MODIFIERS (PRIVATE,PUBLIC,PROTECTED) IS MUST FOR INFORMATION HIDING (ENCAPSULATION).
EACH MODULE COMPLETE BY ITSELF SO CAN PARALLELY DEVELOPED.
IT IS ALWAYS EASY TO DEBUG AND PERFORMANCE TUINING
ENCAPSULATION INCAREASE SYSTEM MODULE REUSE.
INFORMATION HIDING DECREASE THE RISK OF BUILDING LARGER SYSTEMS.