Monday, August 15, 2011

What is Abstraction

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 1400 (Features:- Calling, SMS)
Nokia 2700 (Features:- Calling, SMS, FM Radio, MP3, Camera)
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.

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. 


GAURAV.NET said...

In Abstract Class you have to make both Abstract Methods Thus actually Abstraction is Achieved