answersLogoWhite

0


Best Answer

Data encapsulation refers to a means of limiting data access only to those functions that actually require direct access. Object-oriented programming languages such as C++ use access specifiers (public, private and protected) to determine the accessibility (or visibility) of an object's data or, more specifically, its representation.

  • Public member data is accessible to any function (no encapsulation).
  • Private member data is accessible only to the class member functions and to friends of the class (full encapsulation).
  • Protected member data is the same as private member data and is also accessible to implementers of derived classes and to friends of those classes (partial encapsulation).

For most classes, data members are declared private, thus fully encapsulating the data.

User Avatar

Wiki User

6y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

The ability to make changes in your code without breaking the code of all others who use your code is a key benefit of encapsulation. You should always hide implementation details. To elaborate, you must always have your variables as private and then have a set of public methods that others can use to access your variables. Since the methods are public anyone can access them, but since they are in your class you can ensure that the code works the way that is best for you. So in a situation that you want to alter your code, all you have to do is modify your methods. No one gets hurt because i am just using your method names in my code and the code inside your method doesnt bother me much.

If you want maintainability, flexibility, and extensibility (and I guess, you do), your design must include encapsulation. How do you do that?

• Keep instance variables protected (with an access modifier, mostly private).

• Make public accessor methods, and force calling code to use those methods rather than directly accessing the instance variable.

• For the methods, use the JavaBeans naming convention of set and get.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Encapsulation facilitates the development of a good software product by limiting the dependency by various components on the internal design of other components. With proper encapsulation and rigorously enforced public interfaces, each designer of a component can focus on the task at hand, rather than on the internal aspects of the other components that he or she is using.

If encapsulation and public interfaces are properly designed, then a decision to refactor the private implementation of one component does not lead to a daisy chain of impacts, requiring more refactoring, in other components.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

In c++,Both data members and member functions are encapsulated under single class.Such method of encapsulating both data members and member functions under single class is called Encapsulation.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Data encapsulation ensures that class data members are modified in a highly controlled manner. This is achieved by hiding the data and the implementation details within the class and providing a clearly-defined interface to the consumers of the class. The class' setters ensure that garbage data can never enter the class in the first place, thus eliminating the need for the class mutators to validate the data prior to mutating the class, as well as eliminating the need for consumers to continually validate the data obtained via the class getters. Ultimately this reduces the amount of validation code.

Compare with an exposed variable (non-encapsulated). Any code that has access to that variable can modify it as it sees fit. Therefore all code that uses that variable must ensure the data it contains is in a valid state before it can operate upon it. By encapsulating that variable within a class, the class itself takes care of all validation. Code outwith the class has no access to the variable itself and therefore cannot modify it directly because the class returns a copy of the variable, never the variable itself (if it did, it would not be encapsulated).

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

data encapsulation means to bind data in one form... eg class has data member as well as data function .....

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is data encapsulation in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are the main features of OOP in c plus plus?

The main features of OOP are the same regardless of the language. They are: encapsulation; data hiding; inheritance; and polymorphism.


What is the term that describes the hiding of implementation details of objects from each other in a C plus plus class?

Encapsulation.


What is encapsulation in c?

Assume you were asking as in C#, not C. Because C is not an OO language, thus if there is encapsulation, it would be different.The encapsulation in any OO language is to hide the information of data and the implementation detail of a method.For example, you have a bank account as a private data member. Any one can ask you about the Balance of your bank account, e.g. GetDeposits(), an operation that is public. Wait, you now are richer, and you open 2 more bank accounts, the public still has the only accessing method GetDeposits(), to get your total deposits.The encapsulation in this abstraction are:1. The detail, the implementation of GetDeposits(), is not revealed to public.2. The data member, 1 account or 3 accounts, no one got impact, and no one knows. (in fact, no one knows how many bank accounts you have!)


Is it true that wrapping up of data of different types into a single unit is known as encapsulation?

Not quite. Encapsulation means to combine data and the methods that work upon that data into a single unit (an object), such that access to both the data and methods is restricted in a controlled manner. Data-hiding is fundamental to encapsulation.


How does a class in c plus plus enforce data encapsulation?

Data encapsulation is enforced by restricting access to the class members. Access can be specified on a per-member basis, defaulting to private access for a class and public access for a struct. Private members are accessible to class members and to friends of the class. Protected members are the same as private members but are also accessible to derived class members. Public members are fully-accessible. Data members are typically declared private while interfaces are typically declared public or protected.

Related questions

What are the main features of OOP in c plus plus?

The main features of OOP are the same regardless of the language. They are: encapsulation; data hiding; inheritance; and polymorphism.


What is the term that describes the hiding of implementation details of objects from each other in a C plus plus class?

Encapsulation.


What is encapsulation in c?

Assume you were asking as in C#, not C. Because C is not an OO language, thus if there is encapsulation, it would be different.The encapsulation in any OO language is to hide the information of data and the implementation detail of a method.For example, you have a bank account as a private data member. Any one can ask you about the Balance of your bank account, e.g. GetDeposits(), an operation that is public. Wait, you now are richer, and you open 2 more bank accounts, the public still has the only accessing method GetDeposits(), to get your total deposits.The encapsulation in this abstraction are:1. The detail, the implementation of GetDeposits(), is not revealed to public.2. The data member, 1 account or 3 accounts, no one got impact, and no one knows. (in fact, no one knows how many bank accounts you have!)


Why c plus plus is not complete object oriented language?

because c++ supports all the basic concepts of oop :1.objects,2.classes,3.data abstraction and encapsulation,4.inheritance,5.polymorphism,6.dynamic binding,5.message passing.


What are the concepts of object oriented programming in c plus plus?

The concepts of OOP in C++ are the same as for OOP in any other programming language: abstraction, encapsulation, inheritance and polymorphism.


Is it true that wrapping up of data of different types into a single unit is known as encapsulation?

Not quite. Encapsulation means to combine data and the methods that work upon that data into a single unit (an object), such that access to both the data and methods is restricted in a controlled manner. Data-hiding is fundamental to encapsulation.


What is encapsulation and data hiding in dbms?

ODBMS stands for object oriented database management system. Encapsulation in ODBMS can be defined as binding of data together.


What is pdu encapsulation?

protocol data unit


How does a class in c plus plus enforce data encapsulation?

Data encapsulation is enforced by restricting access to the class members. Access can be specified on a per-member basis, defaulting to private access for a class and public access for a struct. Private members are accessible to class members and to friends of the class. Protected members are the same as private members but are also accessible to derived class members. Public members are fully-accessible. Data members are typically declared private while interfaces are typically declared public or protected.


What has the author Kirk C Benson written?

Kirk C. Benson has written: 'Modeling data encapsulation and a communication network for the National Training Center, Fort Irwin, CA' -- subject(s): SCENARIOS, ENCAPSULATION, ARMY TRAINING, COMMUNICATIONS NETWORKS, MODEL THEORY


Assumptions of 2 phase commit protocol?

to implement real-world entities more and more in computer language and to protect datas we require c++.c++ is basically an object oriented programming language.there are special features which are not present in c such as data encapsulation,data abstraction,polymorphism,inheritance etc.by encapsulation ,we can bind different data types in single unit.by data abstraction ,we can protect our datas.by polymorphism ,we can overload an operator.and by inheritance,we can inherit the properties of the base class.


User defined data type in c plus plus?

Use "typedef" : both in C and C++.