Explain difference between Abstraction and Encapsulation in PHP.
PHP5 added the object-oriented programming approach with the previous version, which is used for making code reusable in real time php application.
Some of the concepts of object-oriented models are: class, object, encapsulation, polymorphism, abstract and final classes, and methods, interfaces and inheritance, etc...
Here we discuss the basic differences between abstraction and encapsulation.
- Encapsulation is an approach that joins data members(variables) and implementation details into a single unit called the class that implies class is formed with variables and methods present inside it.
- Encapsulation is a protection mechanism for data members present inside the class i.e data members are not accessible by end users.
- In encapsulation, the data members(variables) of a class will be not accessible by other classes and can be accessed only through the methods of their current class.
- Encapsulation is implemented using a private and protected access modifier.
- Encapsulation is used for reducing the complexity of a web application
Let's discuss Abstraction.
- The structure of representing necessary features without including the background details is specified as an abstraction.
- Abstraction is the technique of covering the implementation details from the end-user and only displaying the functionality to the users.
- Abstraction is utilized to execute polymorphic ideas with classes i.e With abstraction we can only declare the methods inside a class. usually, another derive class is used to describe the same methods.
- An abstract class cannot be instantiated so end-users can't directly access it.
- It is used to reduce the complexity of the application and make the code reusable in an application.
Published on 11-Jun-2019 09:24:43