Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

What is Data Hiding In C++? Abstraction and Encapsulation Explained

Updated on 18 November, 2022

15.91K+ views
8 min read

Introduction To Data Hiding

Data is the most sensitive and volatile component of a program, which, if manipulated, can result in an incorrect output and harm the integrity of data. This is where data hiding proves essential. In technical jargon, data hiding also referred to as information hiding, is an inherent object-oriented programming mechanism (OOP) to hide internal object details from the end-user.

Data hiding’s underlying objective is to conceal data within a class from unauthorized access and avoid unnecessary penetration from outside the class. Data hiding guarantees constrained data access to ensure object integrity and prevent unintended or intended changes to the program in question.

Simply put, data hiding takes certain parts of a program code and screens it from object members. If an object member is trying to access hidden data, the program will return an error. This is a cautionary mechanism introduced to ensure that the programmer abstains from connecting to erroneous data that has been hidden. It is often the internal components with no foreseeable need on the user’s end that are hidden.  

Check out our free courses to get an edge over the competition.

Data Hiding, Data Abstraction and Data Encapsulation

Data hiding in C++ is closely correlated to two other OOP properties- abstraction and encapsulation. 

Data Abstraction

Data abstraction is a mechanism to expose only the relevant program interface to the end-user and hiding the more intricate and complex implementation details. Let’s consider a real-life example for better understanding. Consider your television. You can turn the television on and off, change the channel, adjust its volume and add external components such as VCRs, DVD players and speakers. But you do not know the internal mechanisms of the television.

You are oblivious to how it receives signals, translates them, and finally displays the output. Thus, television is an adept example of the separation between internal implementation and external influence. With data abstraction, class implementation is protected from inadvertent errors and evolves in response to changing requirements or bug reports without user-level interference. 

Check out upGrad’s Java Bootcamp

Data Encapsulation 

Data encapsulation refers to the bundling of data and their related functions into a single unit called class. Put, if you have an invisible attribute from the outside of an object and bundle it with methods that provide read or write access to it, you can hide delicate information and regulate access to the internal state of the thing.

Therefore, depending on the methods you implement, you are at an onus to decide if an attribute can be read and changed or if it’s read-only or not visible at all. 

Check out upGrad’s Advanced Certification in Blockchain

Difference between data hiding and data encapsulation

In discussing OOP, data hiding and data encapsulation are often used interchangeably because both these notions cooperate to accomplish a common objective-auxiliary gatekeeper of sensitive information. The idea of data encapsulation is undoubtedly functionally comparative to data hiding, but since they work at different levels, they are structurally different.

 Although intrinsically related to each other, there exists a crucial difference between data hiding and data encapsulation.

  1. The main difference between data hiding and encapsulation is that the former focuses on enhancing data security in the program, while the latter deals with hiding the program’s complexity. 
  2. Data hiding concentrates on the accessibility of an object member within a class, while data encapsulation focuses on how the data is accessed and how different objects behave. Encapsulation is mainly accomplished through information hiding and not just information concealing. This means that the programmer hides the object member’s structures and hides the implementation of all its methods.
  3. While data hiding focuses on restricting data use in a program to assure data security, data encapsulation focuses on wrapping (or encapsulating) the complex data to present a simpler view to the user. 
  4. In data hiding, the data has to be defined as private only. In data encapsulation, the data can be public or private. 
  5. Data hiding is both a process and technique in itself, whereas data encapsulation is a sub-process in data hiding. 

Access Specifiers

C++ supports data hiding, and by extension, data abstraction and data encapsulation through the creation of user-defined types, known as classes. The scope of members of this created class is defined by keywords known as access specifiers. Typically, there are three types of protection or access specifiers available within a category- private, protected and public, used to build the class’s encapsulation capabilities.

Access specifiers help define how variables and functions of a type can be accessed from outside the class. Usually, the data within a class is private to eliminate accidental manipulation instances, and its operations are public. However, accessibility within a rank is not bound by any restriction. 

Private variables/functions: Can only be accessed by members defined as part of the class.

Public variables/functions: Can be accessed from anywhere in the program. 

Protected variables/functions Are private within a class and are only available for remote access in the derived class. 

Application Of Data Hiding

To better understand data hiding, let us consider the following example. Considering you are the programmer, let us assume that you declare a class by the name ‘CheckAccount,’ in which you have defined a data member by the term ‘Balance,’ which refers to a user’s bank account balance.

In this particular example, the data member ‘Balance’ is sensitive information. Although you might offer outside application access to view this sensitive information, in all likelihood, you will not let this exterior application alter the attributes of the data stored in the member’ Balance.’ This outcome can be achieved using data hiding, and more specifically, is controlled by the use of the private access specifier. 

  1. Data hiding is commonly executed upon data that is unpredictable and delicate. This kind of data is fundamental in running a program effectively and quickly. Due to unduly access, resulting data changes data are permanent and mandate complete rework on the programmer’s part before further use. 
  2. Data hiding helps protect class members against unintentional overlooks. A class usually comprises various related fields that must be in a reliable state. Suppose a programmer is allowed to control any of these fields straightforwardly. In that case, there is a possibility that you might transform one area without changing critical related fields, leaving your class in a conflicted state.

Benefits Of Data Hiding

The benefits of data hiding are multifold:

  1. It is used to reduce data unpredictability and data complexity.
  2. It improves the reusability of the program. 
  3. By limiting interdependencies between software components, also reduces system complexity for increased robustness. 
  4. Hides the physical stockpiling design for the data. This helps in defining the interface clearly, improves readability and comprehensibility.
  5. It provides data assurance from corruption and unwarranted access. In other words, it helps to conceal important data, thereby ensuring heightened security protocols against hackers. If all internal data were to be made public, hackers could easily penetrate the internal data and make maliciously intended changes to alter the program’s functioning. Hiding the data makes it much harder to crack the code because the hidden data will appear invisible to outside members of the class and, therefore, the hacker. 
  6. The encapsulated classes are straightforward, easy to manage and facilitates future development of the application. 

upGrad’s Exclusive Software and Tech Webinar for you –

SAAS Business – What is So Different?

The Disadvantage Of Data Hiding 

The only disadvantage of data hiding is extra coding. Data hiding necessitates programmers to write lengthier codes to create the desired effect in hidden data. 

Learn Software Engineering Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

Conclusion

Data hiding is akin to a game of Russian Roulette. In Russian Roulette, only one out of six holes have a bullet. Let us imagine the shot is a perceivable data threat. Would you be willing to take a chance? There might exist five scenarios that work in your favour, but can you specifically identify the threat? The answer is no. All the scenarios bear an equal probabilistic burden of suspicion and fear. Instead of giving in to this uncertainty, take a stand against data threats. Go undercover with data hiding. 

If you’re interested to learn more about Java, OOPs & full-stack software development, check out upGrad & IIIT-B’s Executive PG Program in Full-stack Software Development which is designed for working professionals and offers 500+ hours of rigorous training, 9+ projects, and assignments, IIIT-B Alumni status, practical hands-on capstone projects & job assistance with top firms.

Frequently Asked Questions (FAQs)

1. What is encapsulation in object-oriented programming?

Encapsulation is a way of binding together the data and the code that operates on the data. It is a mechanism used to hide the data implementation details while exposing the data abstraction to the outside world. The process of hiding information behind a well-defined interface is known as encapsulation. Encapsulation is a powerful concept of object-oriented programming. It is the process of hiding internal data and operations of an object from the outside world by creating accessor functions.

2. What is abstraction in object-oriented programming?

Abstraction is a technique used in Object-Oriented Programming to separate the interfaces of classes from the implementation details of each individual object. This means that the code can be changed without altering the code which uses the class. In object-oriented programming (OOP), an abstraction represents an object that can be manipulated, but not explicitly defined. Abstraction is an important part of OOP; it is the process of separating the interface of a class from the implementation of its methods.

3. How does classes and objects interact in object-oriented programming?

Classes and objects are the foundation of object-oriented (OO) programming. Object-oriented programming is a programming paradigm, which uses objects and classes to model the real-world. A class is a blueprint or a template. It's a description or a specification of what an object should be. It defines the characteristics, behaviors and data of a particular type of object. Objects are instances or examples of a class. Each and every object in a program can be classified into one or more classes. A class can inherit the properties, methods and other characteristics of another class. This is called as inheritance.

RELATED PROGRAMS