Data Abstraction in PHP
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.
I am giving real life 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 Calling(); // calling function
public SendSMS(); // calling function
}
public class Nokia1400 extends MobilePhone
{
// code here for Nokia 1400 class
}
public class Nokia2700 extends MobilePhone
{
public FMRadio(); // calling function
public MP3(); // calling function
public Camera(); // calling function
}
public class BlackBerry extends MobilePhone
{
public FMRadio(); // calling function
public MP3(); // calling function
public Camera(); // calling function
public Recording(); // calling function
public ReadAndSendEmails(); // calling function
}
Data Abstraction in PHP 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.