1.why do we need encapsulation?2. what is a class in C++ analogous to in C

Showing Answers 1 - 6 of 6 Answers

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;}

  Was this answer useful?  Yes

apiplani

  • Dec 3rd, 2005
 

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.

pratiksha powar

  • Dec 9th, 2005
 

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.

  Was this answer useful?  Yes

sehlhorst

  • Feb 1st, 2006
 

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.

Raja Muthusamy

  • Jun 16th, 2006
 

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.

  Was this answer useful?  Yes

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.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions