Results 1 to 12 of 12

Thread: abstraction Vs encapsulation

  1. #1
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    abstraction Vs encapsulation

    Hi i have some confusion related to the following...

    Abstraction - hiding implementation.
    encapsulation - hiding data.

    Is the above definitions are correct ?
    If yes How these two terms are related? I mean can these things exist without each other?

    ------------------------
    suresh


  2. #2
    Junior Member
    Join Date
    Jul 2007
    Answers
    1

    Thumbs up Re: abstraction Vs encapsulation

    Encapsulation has two faces; data abstraction and information hiding. Data abstraction is a type seen from the outside. Information hiding is a type seen from the inside.

    Sometime encapsulation is used to mean information hiding only but I think the definition I gave is better because if you encapsulate something you get both an inside and an outside right.

    * Abstraction focuses on the outside view of an object (i.e. the interface)



    * Encapsulation (information hiding ) prevents clients from seeing its inside view, where the behavior of the abstraction is implemented


  3. #3

    abstraction vs encapsulation

    Abstraction uses in order to do some works easierly. For example, you have a abstract class fruit. And fruit has some methods one of which has to be abstract . So you should fill the body of this method's body for your each class who are subclass of this abstract class.THe purpoose of it is that to implement method according to that class.

    Abstraction is the process of hiding the details and exposing only the essential features of a particular concept or object.
    Programming is managing complexity. whenwe uses abstraction as a tool for managing complexity in our java pro..

    Encapsulation is the ability of an object to be a container (or capsule) for related properties (ie. data variables) and methods (ie. functions). Programs written in older languages did not enforce any property/method relationship. This often resulted in side effects where variables had their contents changed or reused in unexpected ways and 'spaghetti' code (branching into procedures from external points) that was difficult to unravel, understand and maintain. Encapsulation is one of three fundamental principles within object oriented programming languages.

    Data hiding is the ability of objects to shield variables from external access. These private variables can only be seen or modified by use of object accessor and mutator methods. This permits validity checking at run time. Access to other object variables can be allowed but with tight control on how it is done. Methods can also be completely hidden from external use. Those that are made visible externally can only be called by using the object's front door (ie. there is no 'goto' branching concept).

    public class Box
    {
    // what are the properties or fields
    private int length;
    private int width;
    private int height;

    // what are the actions or methods
    public void setLength(int p)
    {length = p;}

    public void setWidth(int p)
    {width = p;}

    public void setHeight(int p)
    {height = p;}

    public int displayVolume()
    {System.out.println(length*width*height);}
    }

    let me know if you need anymore help


  4. #4
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: abstraction Vs encapsulation

    Some of the threads are merged for better management of the site.

    MODERATOR


  5. #5
    Junior Member
    Join Date
    Sep 2007
    Answers
    1

    Re: abstraction Vs encapsulation

    encapsulation:- it means binding up of data and methods it means the concept of class in which we put together the data members and methods or function members.
    abstraction:- it means that hiding the background details which are not useful to the user for it we use normaly private or protected access specifier.
    by it data is not let free to move around the system.


  6. #6
    Junior Member
    Join Date
    Jun 2007
    Answers
    17

    Re: abstraction Vs encapsulation

    Quote Originally Posted by psuresh1982 View Post
    Hi i have some confusion related to the following...

    Abstraction - hiding implementation.
    encapsulation - hiding data.

    Is the above definitions are correct ?
    If yes How these two terms are related? I mean can these things exist without each other?

    ------------------------
    suresh
    Encapsulation: A simple definition of encapsulation is - combining the data (information) and the methods (functions) that can manipulate that data into one capsule (class/object). Depending on how you write program encapsulation, it guarantees that the encapsulated data is not accessed by any other function/method/program outside the encapsulated object. For example,
    class MyCapsule
    {
    private:
    int myInt;
    char myChar;
    public:
    MyIntFunc() { myInt = 10; }
    MyCharFunc() { myChar = 'A'};
    };

    In this case, no other program/function/method can access myInt other than MyIntFunc. Same is true for myChar and MyCharFunc.

    Abstraction: A simple definition of abstraction is to hide actual implementation of an object from the external world that would use the object. For example, a program that is drawing circles and squares using those objects need not know how those objects are implemented. It is enough for the program to know what the behavior of these objects is, and how to use these objects (rather than how these objects are implemented internally).

    So, drawing a parallel between abstraction and encapsulation, when you encapsulate data and methods that operate on data into one object, the external program that uses this object need not know the internal workings of the object to use the object. Thus making the object abstract data type to the external program. Classic examples of abstract data type in C (yes) are int, char, float, double etc. Classes are OOPL variations and extensions of the traditional abstract data types.
    ------------------------------


  7. #7
    Junior Member
    Join Date
    Jul 2008
    Answers
    1

    Re: abstraction Vs encapsulation

    Abstraction means hiding the internal details and just exposing the functionality. For Example:-When you change the gear of your car, you know the gears will be changed without knowing how they are functioning internally.Abstraction focuses on the outside view of an object (i.e. the interface)

    Encapsulation means put the data and the function that operate on that data in a single unit(information hiding) .Encapsulation prevents clients from seeing its inside view, where the behavior of the abstraction is implemented.


  8. #8
    Junior Member
    Join Date
    Jul 2008
    Answers
    1

    Re: abstraction Vs encapsulation

    hi dear...
    Encapsulation is the process of hiding data member and its functionality on data members.
    Abstraction is the interface which hides the inner functionality.
    Let me explain you with an example...
    Lets say there is switch button.. We know that if press it on... it will work if i press it off.. it stops work.. the switch which is given to you is an abstraction as it is hiding inner details... and wires inside the switch and how there wires are working... all are hidden from us.. is an encapsulation.


  9. #9
    Contributing Member
    Join Date
    Oct 2008
    Answers
    72

    Re: abstraction Vs encapsulation

    Abstraction - Provide a logical, coherent, user friendly interface to an object. The benefit is that you don't need to deal with the (potentially big and complicated) inner workings of the object in order to use it. So you are protecting the user from the object.

    Encapsulation - Package the inner workings of the object securely so the user doesn't even see them. So you are protecting the object from the user.
    Thanks Edit/Delete Message


  10. #10
    Junior Member
    Join Date
    Oct 2008
    Answers
    3

    Re: abstraction Vs encapsulation

    adding more to above ...Abstraction is achieved by proper design to control knowledge of inners of a class to other classes.

    encapsulation can be achieved by using proper access modifiers - public , private,etc to control the scope the vars...encapsultaion promotes separation of state of an object from its behaviour.


  11. #11
    Junior Member
    Join Date
    Mar 2009
    Answers
    10

    Re: abstraction Vs encapsulation

    Encapsulation is hiding what is not needed by the user.

    Abstraction separates the users "view" from the implementation.

    Encapsulation makes things easier for the user of a class by hiding what is not needed by the user.

    Abstraction makes things easier on the implementer of the class. It makes it easier for the class to be changed without requiring the user of the class to change.


  12. #12
    Junior Member
    Join Date
    Nov 2013
    Answers
    1

    Re: abstraction vs encapsulation

    Quote Originally Posted by animesh.chatterjee View Post
    Abstraction uses in order to do some works easierly. For example, you have a abstract class fruit. And fruit has some methods one of which has to be abstract . So you should fill the body of this method's body for your each class who are subclass of this abstract class.THe purpoose of it is that to implement method according to that class.

    Abstraction is the process of hiding the details and exposing only the essential features of a particular concept or object.
    Programming is managing complexity. whenwe uses abstraction as a tool for managing complexity in our java pro..

    Encapsulation is the ability of an object to be a container (or capsule) for related properties (ie. data variables) and methods (ie. functions). Programs written in older languages did not enforce any property/method relationship. This often resulted in side effects where variables had their contents changed or reused in unexpected ways and 'spaghetti' code (branching into procedures from external points) that was difficult to unravel, understand and maintain. Encapsulation is one of three fundamental principles within object oriented programming languages.

    Data hiding is the ability of objects to shield variables from external access. These private variables can only be seen or modified by use of object accessor and mutator methods. This permits validity checking at run time. Access to other object variables can be allowed but with tight control on how it is done. Methods can also be completely hidden from external use. Those that are made visible externally can only be called by using the object's front door (ie. there is no 'goto' branching concept).

    public class Box
    {
    // what are the properties or fields
    private int length;
    private int width;
    private int height;

    // what are the actions or methods
    public void setLength(int p)
    {length = p;}

    public void setWidth(int p)
    {width = p;}

    public void setHeight(int p)
    {height = p;}

    public int displayVolume()
    {System.out.println(length*width*height);}
    }

    let me know if you need anymore help
    This requires a return statement. Based on what you are achieving within the method, this method would also be void


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact