- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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:
- 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.
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.
Advertisements