Thread: How Encapsulation is different from data hiding

  1. #1
    Registered User
    Join Date
    May 2017
    Posts
    101

    How Encapsulation is different from data hiding

    Can anybody tell me How Encapsulation is different from data hiding ?

    I have gone through the book and google search but I do not understand how Encapsulation is different from data hiding

    Encapsulation means to protect sensitive informationin an object by making members protected or private in a class

    Data hiding means to make sure that sensitive data is hidden from user


    Code:
    class Employee {
    private:
    // Private member
    int salary;
    
    public:
    // Setter
    void setSalary(int s) {
          salary = s;
        }
    // Getter
    int getSalary() {
    return salary;
        }
    };

  2. #2
    Registered User
    Join Date
    Aug 2019
    Location
    Inside a Singularity
    Posts
    169
    Encapsulation in C++ - GeeksforGeeks
    Abstraction in C++ - GeeksforGeeks
    Object Oriented Programming in C++ - GeeksforGeeks

    This is the first thing that pops up when you search for "differences between data hiding and encapsulation" which makes me doubt what you googled up.... This is one of many websites that'll give a pretty good knowledge of what the differences are. There are thousands out there.
    Difference Between Data Hiding and Encapsulation (with Comparison Chart) - Tech Difference

    Encapsulation is the act of wrapping things into a single unit. Data hiding is the act of prohibiting data access.

    Your classes are the encapsulators. You encapsulate the data members and methods in the class. You can set different access levels for what kind of access you want to provide to those data members namely: "private" , "protected" and "public". Now you see the difference? Data Hiding can be enforced by Encapsulation. The data that you don't want someone else to directly access, you hide it. But, what makes you able to hide it? It's your encapsulator, the class you use for encapsulation.

  3. #3
    Registered User
    Join Date
    May 2017
    Posts
    101
    Quote Originally Posted by Zeus_ View Post
    This is the first thing that pops up when you search for "differences between data hiding and encapsulation" which makes me doubt what you googled up.... This is one of many websites that'll give a pretty good knowledge of what the differences are. There are thousands out there..
    this page Data encapsulation - Wikipedia say data hiding and encapsulation are the same

    I am confused because i don't see the solid difference between them. What do you they are different or same so if they are different how they are different ?

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    3,687
    Try using the internet links posted above!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Aug 2019
    Location
    Inside a Singularity
    Posts
    169
    > how are they different?

    Did you not read my post?

    There are two sub-links in the Wikipedia page you posted.
    Encapsulation (computer programming) - Wikipedia
    Information hiding - Wikipedia

    Read through them carefully when you get time. Oh, and there is also another link to a comparison chart in my previous post. Encapsulation and Data Hiding are two different things. The former is the enforcer of the latter. If you want to learn OOP, learn it the right way. Be crystal clear with definitions and differences. Good luck
    Last edited by Zeus_; 6 Days Ago at 11:33 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Static functions for data hiding.
    By Lawson in forum C Programming
    Replies: 4
    Last Post: 01-11-2016, 05:01 AM
  2. namespace and data hiding
    By Tux0r in forum C++ Programming
    Replies: 20
    Last Post: 07-09-2009, 05:00 PM
  3. Replies: 10
    Last Post: 06-17-2009, 04:20 PM
  4. Replies: 12
    Last Post: 06-03-2005, 01:13 AM
  5. Replies: 3
    Last Post: 05-25-2005, 01:50 PM

Tags for this Thread