answersLogoWhite

0

What is information hiding in c?

Updated: 11/1/2022
User Avatar

Wiki User

11y ago

Best Answer

Information hiding is employed by object designers to make certain aspects of an object inaccessible to end-users. This is achieved via the access specifiers: public, protected and private.

Private members are accessible to the class itself (including other objects of the same class type) as well as friends of the class type. Protected members are similar to private members but are also accessible to classes that are derived from the class. Public members are fully accessible.

Typically, an object's member variables will be private to the class of object, with public accessors (getters) and mutators (setters) which act as gatekeepers, ensuring the member variables (and therefore the object itself) remain in a valid state at all times. Since objects of the same class type must behave in exactly the same way (as defined by their class), they have privileged access to each other's private members. Friends of the class have similar privileges which is often said to undermine encapsulation. However this is nonsense. Friends extend a class interface, nothing more. You -- the class designer -- are ultimately responsible for ensuring friends of the class do not undermine the encapsulation.

Methods that operate upon the member variables will generally be made public, however any methods that are used internally, solely by the class itself, should remain private to the class.

Protected access is intended for those classes that are intentionally designed to be used as base classes. However, protected access should be limited only to those members that a derived class actually requires access to. While it may be tempting to replace all private accessors to protected, this reduces the effectiveness of the data hiding mechanism. A better solution is to provide protected methods that only derived classes can call.

Remember that all class members are private by default. It is up to you to decide what is made available outside of the class, but as a general rule, less is more. The less you expose, the easier it will be for end-users to use your class.

As an example, imagine a complex class that represents a complex piece of machinery that normally requires the user to complete a check list before invoking a series of start up procedures. In the real world that may well be the case, but in class design, all of that responsibility can be fully encapsulated by the class itself, as private members and methods. The only public member is the start() method, so all the user has to do is hit the start button and the class itself decides if it is good to go. If so, the machine starts, otherwise an error message is displayed. Everything else is completely hidden from the user.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

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

Is there anything similar between C and C plus plus with reference to data hiding?

No. Data hiding is a feature of object oriented programming. C does not support OOP, and therefore has no private member access. All members are public in C.


Why need to declare header files compulsory in c plus plus but not in c?

The need to declare header files is not compulsory in C++. You may place all your code in a single source file if you so desire. However, header files are useful in that they separate interface from implementation and aid in hiding information.


What is information hiding in c plus plus?

I think it more or less refers to the method of program designing in which the modules are constructed in such a way that they do not couple unintentionally with other modules.This means the application software is designed in such a way that the modules or functions in it are not able to access information that they do not need in order to do their job


What is information hiding in software engineering?

The Modules should be designed specifically so that no information(Algorithm and data) contained within the module is not accessible to the other module that have no need of that information. Hiding implies that Effective modularity can be achieved by defining a set of independent modules that communicate with one another only through information necessary to achieve software function.


Why do you use of operator overloading in c?

Overloading, Overriding, Polymorphism, Information Hiding, Inheritance all these are CONCEPTS of C++ and Java. An Object Oriented Language and not of C language. Thats why Bjarne Stroustrup came up with C++ ...

Related questions

What is data hidening in c plus plus?

Data hiding is a property that only relevant information is exposed to the user and rest of the informations remains hidden from the user


Where can one find more information about hiding blogs?

There are many places where one can find more information about hiding blogs. One can find more information about hiding blogs at popular on the web sources such as Square Space and Blogs By Heather.


What did Omar do during hiding?

probably c%% himslef


What is the USA hiding?

The United States is hiding information that it considers would jeopardize its national security.


Is there anything similar between C and C plus plus with reference to data hiding?

No. Data hiding is a feature of object oriented programming. C does not support OOP, and therefore has no private member access. All members are public in C.


What the difference between data hiding and abstraction?

Data hiding means, hiding some essential information or as you say a data from other end user or users and abstraction in simple language means hiding complex features and showing only essential features of any object. Was that information useful please let me know. In data hiding we hide the information by using access specifier private, public and protected..so it means we are hiding info from outside the world.But in abstrastion we express only essential feature.. Eg: Three set of customers are going to buy a bike First one wants information about the style. Second one wants about the milage. Third one wants the cost and brand of the bike.So the salesperson explains about the product which customer needs what. So he hiding some information and giving the revelant information.


Why need to declare header files compulsory in c plus plus but not in c?

The need to declare header files is not compulsory in C++. You may place all your code in a single source file if you so desire. However, header files are useful in that they separate interface from implementation and aid in hiding information.


How will polonius get information when hamlet talks to his mother?

He is hiding in the drapes and he will eavesdrop.


What is Data Hiding in VBNET?

Data hiding is used method used in Object-Oriented programing to hide information within computer code


How is hiding method different from overriding method in c sharp?

Hiding means a class cannot see the definition. Overriding implies that a class must see that to "override"


What is Macbeth hiding from his wife?

Macbeth is hiding the fact that he has murdered King Duncan from his wife, Lady Macbeth. He keeps this information from her to protect her and also to avoid facing her reaction to his heinous act.


What is similar to say hiding the truth?

Keeping information under wraps, withholding information, being deceptive, or being dishonest.