SlideShare a Scribd company logo
1 of 15
Object-Oriented Programming
(OOP)
MD. ATIKUR RAHMAN
PHP
Lecture - 04
Programmer, Silkcity Solution
Trainer, CBA IT
2
Agenda
o Important points to remember while using inheritance
o Overriding Inherited Methods
o Copy Constructor
o Encapsulation
o Abstraction
o Abstraction Vs. Encapsulation
Important points to remember
while using inheritance
o Child class can only access and utilize non-private
parent-class properties and methods.
o Child class can also have its own methods that the
parent class cannot find or access.
o Child class can override and implement a method
specified in parent class.
Overriding
Inherited Methods
o Methods overriding, both parent and child classes should
have same method name with and number of arguments.
o Used to replace parent method in child class.
o The purpose of overriding is to change the behavior of parent
class method.
o The two methods with the same name and same parameter is
called overriding.
5
Overriding Inherited Methods
Example
<?php
class P {
public function geeks() {
echo "Parent<br/>";
}
}
class C extends P {
public function geeks() {
echo "Child";
}
}
$p = new P();
$c = new C();
$p->geeks();
$c->geeks();
?>
OUTPUT
Parent
Child
6
Copy Constructor is a type of constructor which
is used to create a copy of an already existing
object of a class.
Copy
Constructor
7
Copy Constructor
Example
<?php
class CopyConstructor {
public $name;
public function __construct() {
}
public function copyCon(CopyConstructor $object){
$this->name = $object->name;
}
public function show(){
echo "Name = " . $this->name . "<br/>";
}
}
$obj1 = new CopyConstructor();
$obj1->name = 'Copy Constructor';
$obj1->show();
echo '<br/>';
$obj2 = new CopyConstructor();
$obj2->copyCon($obj1);
$obj2->show();
?>
8
Encapsulation is a process of binding the
properties and methods together in a single unit
called class.
Encapsulation
o Declare each property private.
o Create public set method for each property to set the
values of properties.
o Create public get method for each property to get the
values of properties.
Data Encapsulation steps
9
Encapsulation
Example
<?php
class person
{
private $Name, $Age;
public function setNameAge($name, $age) {
$this->Name = $name;
$this->Age = $age;
}
public function displayNameAge() {
echo "Name : ".$this->Name."<br/>";
echo "Age : ".$this->Age."<br/>";
}
};
$pObject = new person();
$pObject->setNameAge("Jhon Luther", 40);
$pObject->displayNameAge();
?>
OUTPUT
Name : Jhon Luther
Age : 40
10
Abstraction is the concept of object-oriented
programming that “shows” only essential attributes
and “hides” unnecessary information.
The main purpose of abstraction is hiding the
unnecessary details from the users.
Abstraction
abstract class Class_Name {
//class code
}
abstract access_modifier function function_name();
abstract class abstract method
11
Abstraction
Rules
o abstract keyword is used to declare an abstract class or method.
o An abstract class must contains at least one abstract method. However, it can also contains
non-abstract methods as well.
o An abstract method has no body. (It has no statements.) It declares an access modifier,
return type, and method signature followed by a semicolon.
o Objects cannot be created from abstract classes.
o If the abstract class uses type hinting (type declaration for return values), the child class
should use the same.
public function myMethod3() : int {...}
o The child class should override (redeclare) all the abstract methods.
o The arguments for methods should be the same as the abstract method.
o The child class can have arguments with default values where the abstract class hasn't
defined.
public function myMethod($name, $age, $country = 'USA') {...}
o The visibility of the child's method should be the same as the parent's or less restricted.
12
Abstraction
Example
<?php
abstract class Person
{
public $name;
public function __construct($name)
{
$this->name = $name;
}
abstract public function greet(): string;
}
?>
Explanation: In the parent class, the __construct method and $name property are declared. So, the
child class will automatically have them. But, greet() is a method that should be defined in all the child
classes and they should return a string.
13
Abstraction
Example (Child Classes)
<?php
class Programmer extends Person {
public function greet(): string {
return "Hello World from ". $this->name;
}
}
class Student extends Person {
public function greet(): string {
return "Howdy! I'm ". $this->name;
}
}
class Teacher extends Person {
public function greet(): string {
return "Good morning dear students";
}
}
$programmer = new Programmer('John');
echo $programmer->greet();
$student = new Student('Doe');
echo $student->greet();
$teacher = new Teacher('Mary');
echo $teacher->greet();
?>
Abstraction Vs. Encapsulation
14
Parameter Abstraction Encapsulation
Use for
Abstraction solves the problem and issues that
arise at the design stage.
Encapsulation solves the problem and issue that
arise at the implementation stage.
Focus
Abstraction allows you to focus on what the
object does instead of how it does it
Encapsulation enables you to hide the code and data
into a single unit to secure the data from the outside
world.
Implementation
You can use abstraction using Interface and
Abstract Class.
You can implement encapsulation using Access
Modifiers (Public, Protected & Private.)
Focuses Focus mainly on what should be done. Focus primarily on how it should be done.
Application During design level. During the Implementation level.
Thank you

More Related Content

Similar to PHP OOP Lecture - 04.pptx

Objects, Testing, and Responsibility
Objects, Testing, and ResponsibilityObjects, Testing, and Responsibility
Objects, Testing, and Responsibilitymachuga
 
Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Chris Tankersley
 
Migration from Procedural to OOP
Migration from Procedural to OOP Migration from Procedural to OOP
Migration from Procedural to OOP GLC Networks
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
PHPID online Learning #6 Migration from procedural to OOP
PHPID online Learning #6 Migration from procedural to OOPPHPID online Learning #6 Migration from procedural to OOP
PHPID online Learning #6 Migration from procedural to OOPAchmad Mardiansyah
 
Object Oriented Programming in PHP
Object Oriented Programming  in PHPObject Oriented Programming  in PHP
Object Oriented Programming in PHPwahidullah mudaser
 
php_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdfphp_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdfakankshasorate1
 
php_final_sy_semIV_notes_vision (3).pdf
php_final_sy_semIV_notes_vision (3).pdfphp_final_sy_semIV_notes_vision (3).pdf
php_final_sy_semIV_notes_vision (3).pdfbhagyashri686896
 
php_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdfphp_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdfHarshuPawar4
 
php_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdfphp_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdfsannykhopade
 
Advanced php
Advanced phpAdvanced php
Advanced phphamfu
 
Demystifying Object-Oriented Programming - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP[tek] 2017Demystifying Object-Oriented Programming - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP[tek] 2017Alena Holligan
 
Php object orientation and classes
Php object orientation and classesPhp object orientation and classes
Php object orientation and classesKumar
 

Similar to PHP OOP Lecture - 04.pptx (20)

Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
Objects, Testing, and Responsibility
Objects, Testing, and ResponsibilityObjects, Testing, and Responsibility
Objects, Testing, and Responsibility
 
Only oop
Only oopOnly oop
Only oop
 
Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016
 
Demystifying oop
Demystifying oopDemystifying oop
Demystifying oop
 
Migration from Procedural to OOP
Migration from Procedural to OOP Migration from Procedural to OOP
Migration from Procedural to OOP
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
PHPID online Learning #6 Migration from procedural to OOP
PHPID online Learning #6 Migration from procedural to OOPPHPID online Learning #6 Migration from procedural to OOP
PHPID online Learning #6 Migration from procedural to OOP
 
Object Oriented Programming in PHP
Object Oriented Programming  in PHPObject Oriented Programming  in PHP
Object Oriented Programming in PHP
 
php_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdfphp_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdf
 
php_final_sy_semIV_notes_vision (3).pdf
php_final_sy_semIV_notes_vision (3).pdfphp_final_sy_semIV_notes_vision (3).pdf
php_final_sy_semIV_notes_vision (3).pdf
 
php_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdfphp_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdf
 
php_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdfphp_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdf
 
OOP in PHP.pptx
OOP in PHP.pptxOOP in PHP.pptx
OOP in PHP.pptx
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
OOP
OOPOOP
OOP
 
Advanced php
Advanced phpAdvanced php
Advanced php
 
Demystifying Object-Oriented Programming - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP[tek] 2017Demystifying Object-Oriented Programming - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP[tek] 2017
 
Php object orientation and classes
Php object orientation and classesPhp object orientation and classes
Php object orientation and classes
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 

Recently uploaded (20)

TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 

PHP OOP Lecture - 04.pptx

  • 1. Object-Oriented Programming (OOP) MD. ATIKUR RAHMAN PHP Lecture - 04 Programmer, Silkcity Solution Trainer, CBA IT
  • 2. 2 Agenda o Important points to remember while using inheritance o Overriding Inherited Methods o Copy Constructor o Encapsulation o Abstraction o Abstraction Vs. Encapsulation
  • 3. Important points to remember while using inheritance o Child class can only access and utilize non-private parent-class properties and methods. o Child class can also have its own methods that the parent class cannot find or access. o Child class can override and implement a method specified in parent class.
  • 4. Overriding Inherited Methods o Methods overriding, both parent and child classes should have same method name with and number of arguments. o Used to replace parent method in child class. o The purpose of overriding is to change the behavior of parent class method. o The two methods with the same name and same parameter is called overriding.
  • 5. 5 Overriding Inherited Methods Example <?php class P { public function geeks() { echo "Parent<br/>"; } } class C extends P { public function geeks() { echo "Child"; } } $p = new P(); $c = new C(); $p->geeks(); $c->geeks(); ?> OUTPUT Parent Child
  • 6. 6 Copy Constructor is a type of constructor which is used to create a copy of an already existing object of a class. Copy Constructor
  • 7. 7 Copy Constructor Example <?php class CopyConstructor { public $name; public function __construct() { } public function copyCon(CopyConstructor $object){ $this->name = $object->name; } public function show(){ echo "Name = " . $this->name . "<br/>"; } } $obj1 = new CopyConstructor(); $obj1->name = 'Copy Constructor'; $obj1->show(); echo '<br/>'; $obj2 = new CopyConstructor(); $obj2->copyCon($obj1); $obj2->show(); ?>
  • 8. 8 Encapsulation is a process of binding the properties and methods together in a single unit called class. Encapsulation o Declare each property private. o Create public set method for each property to set the values of properties. o Create public get method for each property to get the values of properties. Data Encapsulation steps
  • 9. 9 Encapsulation Example <?php class person { private $Name, $Age; public function setNameAge($name, $age) { $this->Name = $name; $this->Age = $age; } public function displayNameAge() { echo "Name : ".$this->Name."<br/>"; echo "Age : ".$this->Age."<br/>"; } }; $pObject = new person(); $pObject->setNameAge("Jhon Luther", 40); $pObject->displayNameAge(); ?> OUTPUT Name : Jhon Luther Age : 40
  • 10. 10 Abstraction is the concept of object-oriented programming that “shows” only essential attributes and “hides” unnecessary information. The main purpose of abstraction is hiding the unnecessary details from the users. Abstraction abstract class Class_Name { //class code } abstract access_modifier function function_name(); abstract class abstract method
  • 11. 11 Abstraction Rules o abstract keyword is used to declare an abstract class or method. o An abstract class must contains at least one abstract method. However, it can also contains non-abstract methods as well. o An abstract method has no body. (It has no statements.) It declares an access modifier, return type, and method signature followed by a semicolon. o Objects cannot be created from abstract classes. o If the abstract class uses type hinting (type declaration for return values), the child class should use the same. public function myMethod3() : int {...} o The child class should override (redeclare) all the abstract methods. o The arguments for methods should be the same as the abstract method. o The child class can have arguments with default values where the abstract class hasn't defined. public function myMethod($name, $age, $country = 'USA') {...} o The visibility of the child's method should be the same as the parent's or less restricted.
  • 12. 12 Abstraction Example <?php abstract class Person { public $name; public function __construct($name) { $this->name = $name; } abstract public function greet(): string; } ?> Explanation: In the parent class, the __construct method and $name property are declared. So, the child class will automatically have them. But, greet() is a method that should be defined in all the child classes and they should return a string.
  • 13. 13 Abstraction Example (Child Classes) <?php class Programmer extends Person { public function greet(): string { return "Hello World from ". $this->name; } } class Student extends Person { public function greet(): string { return "Howdy! I'm ". $this->name; } } class Teacher extends Person { public function greet(): string { return "Good morning dear students"; } } $programmer = new Programmer('John'); echo $programmer->greet(); $student = new Student('Doe'); echo $student->greet(); $teacher = new Teacher('Mary'); echo $teacher->greet(); ?>
  • 14. Abstraction Vs. Encapsulation 14 Parameter Abstraction Encapsulation Use for Abstraction solves the problem and issues that arise at the design stage. Encapsulation solves the problem and issue that arise at the implementation stage. Focus Abstraction allows you to focus on what the object does instead of how it does it Encapsulation enables you to hide the code and data into a single unit to secure the data from the outside world. Implementation You can use abstraction using Interface and Abstract Class. You can implement encapsulation using Access Modifiers (Public, Protected & Private.) Focuses Focus mainly on what should be done. Focus primarily on how it should be done. Application During design level. During the Implementation level.