Encapsulation vs Abstraction?

encapsulation vs abstraction c#
abstraction vs encapsulation in oops with example
abstraction and encapsulation in python
difference between abstraction and encapsulation in java javatpoint
abstraction vs encapsulation in java stack overflow
abstraction in java
abstraction vs interface
how is encapsulation related to abstraction

Here are the brief definitions of encapsulation and abstraction.

Abstraction:

The process of abstraction in Java is used to hide certain details and only show the essential features of the object. In other words, it deals with the outside view of an object (interface). The only good example i see for this across different sites is interface.

Encapsulation:

Its basically about hiding the state of object with the help of modifiers like private,public,protected etc. we expose the state thru public methods only if require.

What we achieve with modifiers like private, public also hides unnecessary details from out side world which is nothing but also a abstraction concept

So, from above explanation looks like encapsulation is a part of abstraction or we can say it's a subset of abstraction. But why then encapsulation term is invented when we could deal it with abstraction only? I am sure there should be some major difference which distinguishes them but most of material on net says almost same thing for both of them.

Though this question has been raised on this forum earlier too but I am posting it again with specific doubts. Some replies also says abstraction is a concept and encapsulation is implementation. But I don't buy this - If it is true, then I can think these two different concepts are provided to confuse us.

Update:- After 5 years i have come up with my own answer whichs is the gist based on answers in this post and below ones

  1. difference between abstraction and encapsulation?
  2. encapsulation vs abstraction real world example

Encapsulation is a strategy used as part of abstraction. Encapsulation refers to the state of objects - objects encapsulate their state and hide it from the outside; outside users of the class interact with it through its methods, but cannot access the classes state directly. So the class abstracts away the implementation details related to its state.

Abstraction is a more generic term, it can also be achieved by (amongst others) subclassing. For example, the interface List in the standard library is an abstraction for a sequence of items, indexed by their position, concrete examples of a List are an ArrayList or a LinkedList. Code that interacts with a List abstracts over the detail of which kind of a list it is using.

Abstraction is often not possible without hiding underlying state by encapsulation - if a class exposes its internal state, it can't change its inner workings, and thus cannot be abstracted.

Abstraction Vs Encapsulation In OOPS, What is the difference between abstraction and encapsulation in Java with examples? Abstraction vs Encapsulation they both are the basic object-oriented programming (OOP) concepts that allow real objects to be implemented in Code and program. They are very different as they both go hand in hand.

Abstraction is the concept of describing something in simpler terms, i.e abstracting away the details, in order to focus on what is important (This is also seen in abstract art, for example, where the artist focuses on the building blocks of images, such as colour or shapes). The same idea translates to OOP by using an inheritance hierarchy, where more abstract concepts are at the top and more concrete ideas, at the bottom, build upon their abstractions. At its most abstract level there is no implementation details at all and perhaps very few commonalities, which are added as the abstraction decreases.

As an example, at the top might be an interface with a single method, then the next level, provides several abstract classes, which may or may not fill in some of the details about the top level, but branches by adding their own abstract methods, then for each of these abstract classes are concrete classes providing implementations of all the remaining methods.

Encapsulation is a technique. It may or may not be for aiding in abstraction, but it is certainly about information hiding and/or organisation. It demands data and functions be grouped in some way - of course good OOP practice demands that they should be grouped by abstraction. However, there are other uses which just aid in maintainability etc.

Difference between Abstraction and Encapsulation in Java, means hiding details of implementation from outside world so that when things change no body gets affected. Abstraction Vs. Encapsulation ; Definition of Encapsulation. Encapsulation is a method of making a complex system easier to handle for end users. The user need not worry about internal details and complexities of the system. Encapsulation is a process of wrapping the data and the code, that operate on the data into a single entity. You can assume it as a protective wrapper that stops random access of code defined outside that wrapper. Abstraction vs. Encapsulation Why you need Abstraction?

OOP Concept for Beginners: What is Encapsulation, ). It describes the idea of bundling data and methods that work on that data within one unit, e.g., a class in Java. This concept is also often used to hide the internal representation, or state, of an object from the outside. Encapsulation and Abstraction are two different but related concepts found in OOP (Object Oriented Programming) languages. Encapsulation is the concept of combining data and behavior together as a single entity. On the other hand, Abstraction is the process of presenting how an entity behaves\looks as opposed to how it is implemented.

Encapsulation is hiding unnecessary data in a capsule or unit

Abstraction is showing essential feature of an object

Encapsulation is used to hide its member from outside class and interface.Using access modifiers provided in c#.like public,private,protected etc. example:

Class Learn
{
  private int a;         // by making it private we are hiding it from other
  private void show()   //class to access it
  {
   console.writeline(a);
  }
}

Here we have wrap data in a unit or capsule i.e Class.

Abstraction is just opposite of Encapsulation.

Abstraction is used to show important and relevant data to user. best real world example In a mobile phone, you see their different types of functionalities as camera, mp3 player, calling function, recording function, multimedia etc. It is abstraction, because you are seeing only relevant information instead of their internal engineering.

 abstract class MobilePhone
    {
        public void Calling();       //put necessary or essential data
        public void SendSMS();       //calling n sms are main in mobile
    }

    public class BlackBerry : MobilePhone   // inherited main feature
    {
        public void FMRadio();            //added new
        public void MP3();
        public void Camera();
        public void Recording();

    }

How to say that abstraction can't be done without encapsulation , As in encapsulation, the data in a class is hidden from other classes, so it is also known as data-hiding. Encapsulation can be achieved by Declaring all the  Encapsulation is a process of developing a complex system much easier to manage end user, without worrying about its inner complexities. The difference between abstraction and encapsulation is that abstraction focuses on identifying the essential components for building a system while encapsulation focuses on hiding the inner complexities of a system.

Abstraction is a very general term, and abstraction in software is not limited to object-oriented languages. A dictionary definition: "the act of considering something as a general quality or characteristic, apart from concrete realities, specific objects, or actual instances".

Assembly language can be thought of as an abstraction of machine code -- assembly expresses the essential details and structure of the machine code, but frees you from having to think about the opcodes used, the layout of the code in memory, making jumps go to the right address, etc.

Your operating system's API is an abstraction of the underlying machine. Your compiler provides a layer of abstraction which shields you from the details of assembly language. The TCP/IP stack built into your operating system abstracts away the details of transmitting bits over a network. If you go down all the way to the raw silicon, the people who designed your CPU did so using circuit diagrams written in terms of "diodes" and "transistors", which are abstractions of how electrons travel through semiconductor crystals.

In software, everything is an abstraction. We build programs which simulate or model some aspect of reality, but by necessity our models always abstract away some details of the "real thing". We build layer on layer on layer of abstractions, because it is the only way we get anything done. (Imagine you were trying to make, say, a sudoku solver, and you had to design it using only semiconductor crystals. "OK, I need a piece of N-type silicon here...")

In comparison, "encapsulation" is a very specific and limited term. Some of the other answers to this question have already given good definitions for it.

Difference between Abstraction and Encapsulation in Java with , Abstraction vs. Encapsulation. Why you need Abstraction? Here, are the main reasons why abstraction is needed for Object-Oriented  Encapsulation is one of the four fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction. Encapsulation in Java is a mechanism for wrapping the data (variables) and code acting on the data (methods) together as a single unit.

Difference between Abstraction and Encapsulation, Encapsulation. Encapsulation is one of the four fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction. The main difference between Encapsulation and Abstraction in C# is that the encapsulation wraps the data and methods into a single unit while abstraction hides the implementation details and only displays the functionality to users.

Abstraction vs Encapsulation in Java, Most answers here focus on OOP but encapsulation begins much earlier: Every function is an encapsulation; in pseudocode: point x = { 1, 4 }  Abstraction: Encapsulation: Abstraction solves the problem in the design level. Encapsulation solves the problem in the implementation level. Abstraction is used for hiding the unwanted data and giving onlyrelevant data. Encapsulation is hiding the code and data into a single unit toprotect the data from outer world.

Difference between abstraction and encapsulation?, Encapsulate hides variables or some implementation that may be changed so often in a class to prevent outsiders access it directly. They must  Encapsulation is a process of hiding all the internal details of an object from the outside real world. The word "encapsulation", is like "enclosing" into a "capsule". It restricts clients from seeing its internal view where the behavior of the abstraction is implemented.

Comments
  • encapsulation as defined above is a tool of abstraction however I tend to think of it in terms as what a class encapsulates (functionality/data regardless of access) where as abstraction is more a sense of removing you from concerns of concrete implementations i.e. regardless of how it is done and what exactly is done it is doable from wikipedia An 'abstraction' (noun) is a concept that acts as a super-categorical noun for all subordinate concepts, and connects any related concepts as a group, field, or category.
  • Encapsulation is more of binding the relevant details(data and behaviors that operate on the data) relating to context. It can also be achieved with out access specifiers like private public , as they only provide information/data hiding which we do it because it is a good practice to protect the data of the instance.
  • Encapsulation means that a group of related properties, methods, and other members are treated as a single unit or object. msdn.microsoft.com/en-us/library/dd460654.aspx
  • Encapsulation leads to Abstraction.
  • Your definition of Abstraction is the best I have EVER seen, and I feel like for the first time ever, it actually clicked in my head and made sense. I know it's been 3+ years since you posted this, but thank you.
  • Wow.... Abstraction.... expressed in terms of art... red might be anger, that's all we needed to know! Thank you for this view of the concept :-)
  • Encapsulation is used to achieve "Loose Coupling & High Cohesion."
  • Can we say Abstraction is a kind of design concept and Encapsulation mainly concerns about implementation of design we agreed upon during abstraction?
  • In encapsulation you define operations that can/must be applied to your data.This can be part of the design as well.E.g. retrieve SSN, but not modify it
  • i agree. these guys are sorta opposites. good oop tends to abstract the things that do not change and to [encapsulate the tings that do change][1]. [1]: principles-wiki.net/…