Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to understand the definition of 'abstraction' in OOP.

I have come across a few main definitions. Are they all valid? Is one of them wrong? I'm confused. (I re-wrote the definition with my own words).

Definition 1:

Abstraction is the concept of taking some object from the real world, and converting it to programming terms. Such as creating a Human class and giving it int health, int age, String name, etc. properties, and eat() etc. methods.

Definition 2:

A more general definition. Abstraction is a concept that takes place anywhere in a software system where 'making things more general/simpler/abstract' is involved. A few examples:

  • An inheritance hierarchy, where the higher classes are simpler or more general, and define more general and abstract implementation. While the lower classes in the hierarchy are more concrete and define more detailed implementations.

  • Using encapsulation to hide the details of implementation of a class from other classes, thus making the class more 'abstract' (simpler) to the outside software world.

Definition 3

Another general definition: Abstraction is the concept of moving the focus from the details and concrete implementation of things, to the types of things (i.e. classes), the operations available (i.e. methods), etc, thus making the programming simpler, more general, and more abstract. (This can take place anywhere and in any context in the software system). It takes place for example when encapsulating, because encapsulation means to hide the details of implementation and only show the types of things and their more general and abstract definitions. Anotehr example would be using a List object in Java. this object actually uses the implementation details of an ArrayList or a LinkedList, but this information is abstracted using the more general name List.

Is any of these definitions correct? (I am referring to the most conventional and accepted definition).

share|improve this question
up vote 10 down vote accepted

Abstraction is one of the 3 pillars of Object Oriented Programming(OOP). It literally means to perceive an entity in a system or context from a particular perspective. We take out unnecessary details and only focus on aspects that are necessary to that context or system under consideration.

Here is some good explanation:

You as a person have different relationships in different roles. When you are at school, then you are a "Student". When you are at work, you are an "Employee". When you are at government institution, you can be viewed as a "Citizen". So it boils down to what in what context are we looking at an entity/object. So if I am modelling a Payroll System, I will look at you as an Employee(PRN, Full Time/Part Time, Designation). If am modelling a Course Enrollment System, then I will consider your aspects and characteristics as a Student(Roll Number, Age, Gender, Course Enrolled). And if I am modelling a Social Security Information System then I will look at your details as a Citizen(like DOB, Gender, Country Of Birth, etc.)

Remember that Abstraction(focussing on necessary details) is different from Encapsulation(hiding details from the outer world). Encapsulation means hiding the details of the object and providing a decent interface for the entities in outer world to interact with that object or entity. For example, if someone want to know my name then he cannot directly access my brain cells to get to know what is my name. Instead that person will either ask my name. If a driver wants to speed up a vehicle then there is an interface(accelerator pedal, gear, etc) for that purpose.

The 1st def s not very clear. Def 2 is good but it tends to confuse the newbie as it tries to link Abstraction with Encapsulation and Inheritance. Def 3 is the best one out of 3 definitions as it clearly defines what is Abstraction precisely.

share|improve this answer
So you would say that it's like a generalization instead of a specification? – Robert Rocha Jan 6 '15 at 0:50
@samyismyhero Exactly! We look for generic attributes and behavior of objects for abstraction. – Maxood Jan 7 '15 at 7:41

Definition 1 is definitely not an abstraction. That is more closely describing modeling.

Definitions 2 and 3 describe same thing. And both are pretty good descriptions of an abstraction.

share|improve this answer
That's what I thought! abstract class Shape lol! – Robert Rocha Jan 6 '15 at 0:52

Each of these definitions is fine.

Abstraction is where you focus on only those details that are important for your purpose.

In the first case, you (at present) cannot include real people in your code; you focus on particular details of a person that serve your purpose. In another program you may need to focus on different details. These would be different abstractions of a person, and each can be equally valid in their context.

The second and third definitions continue this idea, applying it to software entities.

share|improve this answer

protected by gnat Aug 16 '15 at 10:41

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.