Smali
Smali

Reputation: 11

What is the real definition of Abstraction?

I have seen different meanings for abstraction in several web sites.

Some sites say that

Selecting relevant data and ignoring insignificant data

Some sites say that

Taking common class from same kind of objects

As a example Vehicle class can be taken as Abstract when compare with bus, lorry and car.

I confused with these definitions.. What is the correct one?

Upvotes: 1

Views: 215

Answers (3)

Aarif Shaikh
Aarif Shaikh

Reputation: 17

The simplest definition of abstraction is "Hiding the implementation details from its specifications". The Best Real time example is: Suppose you are a driver then you need to know "How to drive a car(its specification) ", Not the implementation details of car(like how engine is build etc.).

Simplest programming example is System.out.println() function.As a programmer you need to know how to use System.out.println(), not its implementation details. hope it clears you doubt.

Upvotes: 1

Program-Me-Rev
Program-Me-Rev

Reputation: 6624

Abstraction is "To represent the essential feature without representing the back ground details."

Abstraction lets you focus on what the object does instead of how it does it.

Abstraction provides you a generalized view of your classes or object by providing relevant information.

Abstraction is the process of hiding the working style of an object, and showing the information of an object in understandable manner.

Real world Example of Abstraction: -

Suppose you have an object Mobile Phone.

Suppose you have 3 mobile phones as following:-

  • Nokia 2700 (Features:- Calling, SMS, FM Radio, MP3, Camera)
  • Black Berry (Features:-Calling, SMS, FM Radio, MP3, Camera, Video Recording, Reading E-mails)
  • Black Berry (Features:-Calling, SMS, FM Radio, MP3, Camera, Video Recording, Reading E-mails)

Abstract information (Necessary and Common Information) for the object "Mobile Phone" is make a call to any number and can send SMS."

so that, for mobile phone object you will have abstract class like following:-

abstract class MobilePhone
{
    public void Calling();
    public void SendSMS();
}

public class Nokia1400 : MobilePhone
{

}

public class Nokia2700 : MobilePhone
{
    public void FMRadio();
    public void MP3();
    public void Camera();
}

public class BlackBerry : MobilePhone
{
    public void FMRadio();
    public void MP3();
    public void Camera();
    public void Recording();
    public void ReadAndSendEmails();

}

Abstraction means putting all the variables and methods in a class which are necessary.

For example: - Abstract class and abstract method.

Abstraction is the common thing:

Example:

If somebody in your collage tell you to fill application form, you will fill your details like name, address, data of birth, which semester, percentage you have got etc. If some doctor gives you an application to fill the details, you will fill the details like name, address, date of birth, blood group, height and weight.

See in the above example what is the common thing? Age, name, address - So you can create the class which consist of common thing that is called abstract class. That class is not complete and it can inherit by other class.

Upvotes: 0

Max Tkachenko
Max Tkachenko

Reputation: 504

Abstraction is the ability to work with the high-level concept while ignoring low-level details.

I like the example I saw in McConnell book "Code complete":

If you refer to an object as "house" rather than a combination of wood, glass and nails, you are using an abstraction.

Upvotes: 0

Related Questions