SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
WELCOME TO ‘INTRO TO OOP WITH PHP’
Thank you for your interest. Files can be found at https://
github.com/sketchings/oop-basics
Contact Info:
www.sketchings.com
@sketchings
alena@holligan.us
INTRO TO OOP WITH PHP (INTRODUCTION)
A BASIC LOOK INTO OBJECT-ORIENTED PROGRAMMING
WHAT IS OOP?
➔Object-Oriented Programing
➔A programming concept that treats functions and
data as objects.
➔A programming methodology based on objects,
instead of functions and procedures
OOP VS PROCEDURAL OR FUNCTIONAL
• OOP is built around the "nouns", the things in the
system, and what they are capable of
• Whereas procedural or functional programming
is built around the "verbs" of the system, the
things you want the system to do
LET’S GET INTO SOME EXAMPLES
Files can be found at https://github.com/
sketchings/oop-basics
Contact Info:
www.sketchings.com
@sketchings
alena@holligan.us
WELCOME TO ‘INTRO TO OOP WITH PHP’
PART 1
Thank you for your interest. Files can be found at https://
github.com/sketchings/oop-basics
Contact Info:
www.sketchings.com
@sketchings
alena@holligan.us
INTRO TO OOP WITH PHP (PART 1)
A BASIC LOOK INTO OBJECT-ORIENTED PROGRAMMING
TERMINOLOGY
THE SINGLE MOST IMPORTANT PART
TERMS
• Class (properties, methods)
• Object
• Instance
• Abstraction
• Encapsulation
• Inheritance
CLASS
• A template/blueprint that facilitates creation of objects.
A set of program statements to do a certain task. Usually
represents a noun, such as a person, place or thing.
• Includes properties and methods — which are class
functions
OBJECT
• Instance of a class.
• In the real world object is a material thing that
can be seen and touched.
• In OOP, object is a self-contained entity that
consists of both data and procedures.
INSTANCE
• Single occurrence/copy of an object
• There might be one or several objects, but an
instance is a specific copy, to which you can have
a reference
class User { //class
private $name; //property
public getName() { //method
echo $this->name;
}
}
$user1 = new User(); //first instance of object
$user2 = new User(); //second instance of object
ABSTRACTION
• “An abstraction denotes the essential characteristics
of an object that distinguish it from all other kinds of
object and thus provide crisply defined conceptual
boundaries, relative to the perspective of the viewer.”

— G. Booch
• This is the class architecture itself.
ENCAPSULATION
• Scope. Controls who can access what. Restricting
access to some of the object’s components (properties
and methods), preventing unauthorized access.
• Public - everyone
• Protected - inherited classes
• Private - class itself, not children
• class User {

protected $name;

protected $title;

public function getFormattedSalutation() {

return $this->getSalutation();

}

protected function getSalutation() {

return $this->title . " " . $this->name;

}

public function getName() {

return $this->name;

}

public function setName($name) {

$this->name = $name;

}

public function getTitle() {

return $this->title;

}

public function setTitle($title) {

$this->title = $title;

}

}
CREATING / USING THE OBJECT INSTANCE
$user = new User();

$user->setName("Jane Smith");

$user->setTitle("Ms");

echo $user->getFormattedSalutation();
When the script is run, it will return:
Ms Jane Smith
CONSTRUCTOR METHOD & MAGIC METHODS
class User {

protected $name;

protected $title;



public function __construct($name, $title) {

$this->name = $name;

$this->title = $title;

}



public function __toString() {

return $this->getFormattedSalutation();

}

...

}
For more see http://php.net/manual/en/language.oop5.magic.php
CREATING / USING THE OBJECT INSTANCE
$user = new User("Jane Smith","Ms");

echo $user;
When the script is run, it will return the same result as before:
Ms Jane Smith
INHERITANCE: PASSES KNOWLEDGE DOWN
• Subclass, parent and a child relationship, allows for
reusability, extensibility.
• Additional code to an existing class without modifying it.
Uses keyword “extends”
• NUTSHELL: create a new class based on an existing class
with more data, create new objects based on this class
CREATING AND USING A CHILD CLASS
class Developer extends User {

public $skills = array();

public function getSalutation() {

return $this->title . " " . $this->name. ", Developer";

}

public function getSkillsString() {

echo implode(", ",$this->skills);

}

}
$developer = new Developer("Jane Smith", "Ms");

echo $developer;

echo "<br />";

$developer->skills = array("JavasScript", "HTML", "CSS");

$developer->skills[] = "PHP";

$developer->getSkillsString();
WHEN RUN, THE SCRIPT RETURNS:
Ms Jane Smith
JavasScript, HTML, CSS, PHP
FINISHED
QUESTION AND ANSWER TIME
THANK YOU FROM ALENA HOLLIGAN
Files at https://github.com/sketchings/oop-basics
Contact Info:
www.sketchings.com
@sketchings
alena@holligan.us
WELCOME TO ‘INTRO TO OOP WITH
PHP’ PART 2
Thank you for your interest. Files can be found at https://github.com/
sketchings/oop-basics
Contact Info:
www.sketchings.com
@sketchings
alena@holligan.us
INTRO TO OOP WITH PHP (PART 2)
A BASIC LOOK INTO OBJECT-ORIENTED PROGRAMMING
TERMINOLOGY
THE SINGLE MOST IMPORTANT PART
TERMS
• Class (properties, methods)
• Object
• Instance
• Abstraction
• Encapsulation
• Inheritance
TERMS CONTINUED
• Polymorphism
• Interface
• Abstract
• Type Hinting
• Namespaces
POLYMORPHISM
Polymorphism describes a pattern in object oriented programming in
which classes have different functionality while sharing a common
interface
INTERFACE
• Interface, specifies which methods a class must implement.
• All methods in interface must be public.
• Multiple interfaces can be implemented by using comma separation
• Interface may contain a CONSTANT, but may not be overridden by
implementing class
interface UserInterface {
public function getFormattedSalutation();
public function getName();
public function setName($name);
public function getTitle();
public function setTitle($title);
}
class User implements UserInterface { … }
ABSTRACT
An abstract class is a mix between an interface and a class. It can define
functionality as well as interface (in the form of abstract methods).
Classes extending an abstract class must implement all of the abstract
methods defined in the abstract class.
abstract class User { //class
public $name; //property
public getName() { //method
echo $this->name;
}
abstract public function setName($name);
}
class Developer extends User { … }
NAMESPACES
• Help create a new layer of code encapsulation
• Keep properties from colliding between areas of your code
• Only classes, interfaces, functions and constants are
affected
• Anything that does not have a namespace is considered in
the Global namespace (namespace = "")
NAMESPACES
• must be declared first (except 'declare)
• Can define multiple in the same file
• You can define that something be used in the "Global" namespace by
enclosing a non-labeled namespace in {} brackets.
• Use namespaces from within other namespaces, along with aliasing
• namespace myUser;
• class User { //class
• public $name; //property
• public getName() { //method
• echo $this->name;
• }
• public function setName($name);
• }
• class Developer extends myUserUser { … }
EXPLANATION COMPLETE
QUESTION AND ANSWER TIME
CHALLENGES
1. Change to User class to an abstract class.
2. Throw an error because your access is too restricted.
3. Extend the User class for another type of user, such as our
Developer example
4. Define 2 “User” classes in one file using namespacing
THANK YOU FROM ALENA HOLLIGAN
I hope you enjoyed this presentation and learned a lot in the
short time we had. Please stay tuned for more and fill out the
survey to help improve the training.
Contact Info:
www.sketchings.com
@sketchings
alena@holligan.us
RESOURCES
• LeanPub: The essentials of Object Oriented PHP

Contenu connexe

Tendances

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
 
Intro to OOP PHP and Github
Intro to OOP PHP and GithubIntro to OOP PHP and Github
Intro to OOP PHP and GithubJo Erik San Jose
 
Synapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindiappsdevelopment
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHPMichael Peacock
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHPVibrant Technologies & Computers
 
Oop in-php
Oop in-phpOop in-php
Oop in-phpRajesh S
 
Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPWildan Maulana
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3Toni Kolev
 
Advanced php
Advanced phpAdvanced php
Advanced phphamfu
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5Jason Austin
 
Anonymous Classes: Behind the Mask
Anonymous Classes: Behind the MaskAnonymous Classes: Behind the Mask
Anonymous Classes: Behind the MaskMark Baker
 
Class and Objects in PHP
Class and Objects in PHPClass and Objects in PHP
Class and Objects in PHPRamasubbu .P
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPsRavi Bhadauria
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in phpCPD INDIA
 

Tendances (20)

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
 
Intro to OOP PHP and Github
Intro to OOP PHP and GithubIntro to OOP PHP and Github
Intro to OOP PHP and Github
 
Synapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindia object oriented programming in php
Synapseindia object oriented programming in php
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
Php Oop
Php OopPhp Oop
Php Oop
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
Oop in-php
Oop in-phpOop in-php
Oop in-php
 
Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOP
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3
 
Advanced php
Advanced phpAdvanced php
Advanced php
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5
 
Anonymous Classes: Behind the Mask
Anonymous Classes: Behind the MaskAnonymous Classes: Behind the Mask
Anonymous Classes: Behind the Mask
 
Class and Objects in PHP
Class and Objects in PHPClass and Objects in PHP
Class and Objects in PHP
 
Introduction to php oop
Introduction to php oopIntroduction to php oop
Introduction to php oop
 
Oops in php
Oops in phpOops in php
Oops in php
 
PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 

Similaire à Demystifying Object-Oriented Programming #ssphp16

Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Alena Holligan
 
Demystifying Object-Oriented Programming - Midwest PHP
Demystifying Object-Oriented Programming - Midwest PHPDemystifying Object-Oriented Programming - Midwest PHP
Demystifying Object-Oriented Programming - Midwest PHPAlena Holligan
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Alena Holligan
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Alena Holligan
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxShaownRoy1
 
Demystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPDemystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPAlena Holligan
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeDhivyaa C.R
 
Objects, Testing, and Responsibility
Objects, Testing, and ResponsibilityObjects, Testing, and Responsibility
Objects, Testing, and Responsibilitymachuga
 
PHP-05-Objects.ppt
PHP-05-Objects.pptPHP-05-Objects.ppt
PHP-05-Objects.pptrani marri
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2Mudasir Syed
 
10 PHP Design Patterns #burningkeyboards
10 PHP Design Patterns #burningkeyboards10 PHP Design Patterns #burningkeyboards
10 PHP Design Patterns #burningkeyboardsDenis Ristic
 

Similaire à Demystifying Object-Oriented Programming #ssphp16 (20)

Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017
 
Demystifying Object-Oriented Programming - Midwest PHP
Demystifying Object-Oriented Programming - Midwest PHPDemystifying Object-Oriented Programming - Midwest PHP
Demystifying Object-Oriented Programming - Midwest PHP
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
 
Demystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPDemystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHP
 
Only oop
Only oopOnly oop
Only oop
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
 
Demystifying oop
Demystifying oopDemystifying oop
Demystifying oop
 
Objects, Testing, and Responsibility
Objects, Testing, and ResponsibilityObjects, Testing, and Responsibility
Objects, Testing, and Responsibility
 
PHP-05-Objects.ppt
PHP-05-Objects.pptPHP-05-Objects.ppt
PHP-05-Objects.ppt
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
Let's Talk Scope
Let's Talk ScopeLet's Talk Scope
Let's Talk Scope
 
Chapter iii(oop)
Chapter iii(oop)Chapter iii(oop)
Chapter iii(oop)
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
 
10 PHP Design Patterns #burningkeyboards
10 PHP Design Patterns #burningkeyboards10 PHP Design Patterns #burningkeyboards
10 PHP Design Patterns #burningkeyboards
 
Jscript part2
Jscript part2Jscript part2
Jscript part2
 
Oops concept in php
Oops concept in phpOops concept in php
Oops concept in php
 

Plus de Alena Holligan

2023 Longhorn PHP - Learn to Succeed .pdf
2023 Longhorn PHP - Learn to Succeed .pdf2023 Longhorn PHP - Learn to Succeed .pdf
2023 Longhorn PHP - Learn to Succeed .pdfAlena Holligan
 
Environmental variables
Environmental variablesEnvironmental variables
Environmental variablesAlena Holligan
 
Experiential Project Design
Experiential Project DesignExperiential Project Design
Experiential Project DesignAlena Holligan
 
Organization Patterns: MVC
Organization Patterns: MVCOrganization Patterns: MVC
Organization Patterns: MVCAlena Holligan
 
When & Why: Interfaces, abstract classes, traits
When & Why: Interfaces, abstract classes, traitsWhen & Why: Interfaces, abstract classes, traits
When & Why: Interfaces, abstract classes, traitsAlena Holligan
 
Obect-Oriented Collaboration
Obect-Oriented CollaborationObect-Oriented Collaboration
Obect-Oriented CollaborationAlena Holligan
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressAlena Holligan
 
Exploiting the Brain for Fun and Profit
Exploiting the Brain for Fun and ProfitExploiting the Brain for Fun and Profit
Exploiting the Brain for Fun and ProfitAlena Holligan
 
Environmental Variables
Environmental VariablesEnvironmental Variables
Environmental VariablesAlena Holligan
 
Exploiting the Brain for Fun & Profit #zendcon2016
Exploiting the Brain for Fun & Profit #zendcon2016Exploiting the Brain for Fun & Profit #zendcon2016
Exploiting the Brain for Fun & Profit #zendcon2016Alena Holligan
 
Presentation Bulgaria PHP
Presentation Bulgaria PHPPresentation Bulgaria PHP
Presentation Bulgaria PHPAlena Holligan
 
Exploiting the Brain for Fun and Profit - Lone Star 2016
Exploiting the Brain for Fun and Profit - Lone Star 2016Exploiting the Brain for Fun and Profit - Lone Star 2016
Exploiting the Brain for Fun and Profit - Lone Star 2016Alena Holligan
 
Exploiting the Brain for Fun & Profit #ssphp16
Exploiting the Brain for Fun & Profit #ssphp16Exploiting the Brain for Fun & Profit #ssphp16
Exploiting the Brain for Fun & Profit #ssphp16Alena Holligan
 

Plus de Alena Holligan (20)

2023 Longhorn PHP - Learn to Succeed .pdf
2023 Longhorn PHP - Learn to Succeed .pdf2023 Longhorn PHP - Learn to Succeed .pdf
2023 Longhorn PHP - Learn to Succeed .pdf
 
Environmental variables
Environmental variablesEnvironmental variables
Environmental variables
 
Dev parent
Dev parentDev parent
Dev parent
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Dependency Management
Dependency ManagementDependency Management
Dependency Management
 
Experiential Project Design
Experiential Project DesignExperiential Project Design
Experiential Project Design
 
Reduce Reuse Refactor
Reduce Reuse RefactorReduce Reuse Refactor
Reduce Reuse Refactor
 
Organization Patterns: MVC
Organization Patterns: MVCOrganization Patterns: MVC
Organization Patterns: MVC
 
When & Why: Interfaces, abstract classes, traits
When & Why: Interfaces, abstract classes, traitsWhen & Why: Interfaces, abstract classes, traits
When & Why: Interfaces, abstract classes, traits
 
Object Features
Object FeaturesObject Features
Object Features
 
Obect-Oriented Collaboration
Obect-Oriented CollaborationObect-Oriented Collaboration
Obect-Oriented Collaboration
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPress
 
Exploiting the Brain for Fun and Profit
Exploiting the Brain for Fun and ProfitExploiting the Brain for Fun and Profit
Exploiting the Brain for Fun and Profit
 
Environmental Variables
Environmental VariablesEnvironmental Variables
Environmental Variables
 
Learn to succeed
Learn to succeedLearn to succeed
Learn to succeed
 
Exploiting the Brain for Fun & Profit #zendcon2016
Exploiting the Brain for Fun & Profit #zendcon2016Exploiting the Brain for Fun & Profit #zendcon2016
Exploiting the Brain for Fun & Profit #zendcon2016
 
Presentation Bulgaria PHP
Presentation Bulgaria PHPPresentation Bulgaria PHP
Presentation Bulgaria PHP
 
Presentation pnwphp
Presentation pnwphpPresentation pnwphp
Presentation pnwphp
 
Exploiting the Brain for Fun and Profit - Lone Star 2016
Exploiting the Brain for Fun and Profit - Lone Star 2016Exploiting the Brain for Fun and Profit - Lone Star 2016
Exploiting the Brain for Fun and Profit - Lone Star 2016
 
Exploiting the Brain for Fun & Profit #ssphp16
Exploiting the Brain for Fun & Profit #ssphp16Exploiting the Brain for Fun & Profit #ssphp16
Exploiting the Brain for Fun & Profit #ssphp16
 

Dernier

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Demystifying Object-Oriented Programming #ssphp16

  • 1. WELCOME TO ‘INTRO TO OOP WITH PHP’ Thank you for your interest. Files can be found at https:// github.com/sketchings/oop-basics Contact Info: www.sketchings.com @sketchings alena@holligan.us
  • 2. INTRO TO OOP WITH PHP (INTRODUCTION) A BASIC LOOK INTO OBJECT-ORIENTED PROGRAMMING
  • 3. WHAT IS OOP? ➔Object-Oriented Programing ➔A programming concept that treats functions and data as objects. ➔A programming methodology based on objects, instead of functions and procedures
  • 4. OOP VS PROCEDURAL OR FUNCTIONAL • OOP is built around the "nouns", the things in the system, and what they are capable of • Whereas procedural or functional programming is built around the "verbs" of the system, the things you want the system to do
  • 5. LET’S GET INTO SOME EXAMPLES Files can be found at https://github.com/ sketchings/oop-basics Contact Info: www.sketchings.com @sketchings alena@holligan.us
  • 6. WELCOME TO ‘INTRO TO OOP WITH PHP’ PART 1 Thank you for your interest. Files can be found at https:// github.com/sketchings/oop-basics Contact Info: www.sketchings.com @sketchings alena@holligan.us
  • 7. INTRO TO OOP WITH PHP (PART 1) A BASIC LOOK INTO OBJECT-ORIENTED PROGRAMMING
  • 9. TERMS • Class (properties, methods) • Object • Instance • Abstraction • Encapsulation • Inheritance
  • 10. CLASS • A template/blueprint that facilitates creation of objects. A set of program statements to do a certain task. Usually represents a noun, such as a person, place or thing. • Includes properties and methods — which are class functions
  • 11. OBJECT • Instance of a class. • In the real world object is a material thing that can be seen and touched. • In OOP, object is a self-contained entity that consists of both data and procedures.
  • 12. INSTANCE • Single occurrence/copy of an object • There might be one or several objects, but an instance is a specific copy, to which you can have a reference
  • 13. class User { //class private $name; //property public getName() { //method echo $this->name; } } $user1 = new User(); //first instance of object $user2 = new User(); //second instance of object
  • 14. ABSTRACTION • “An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of object and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer.”
 — G. Booch • This is the class architecture itself.
  • 15. ENCAPSULATION • Scope. Controls who can access what. Restricting access to some of the object’s components (properties and methods), preventing unauthorized access. • Public - everyone • Protected - inherited classes • Private - class itself, not children
  • 16. • class User {
 protected $name;
 protected $title;
 public function getFormattedSalutation() {
 return $this->getSalutation();
 }
 protected function getSalutation() {
 return $this->title . " " . $this->name;
 }
 public function getName() {
 return $this->name;
 }
 public function setName($name) {
 $this->name = $name;
 }
 public function getTitle() {
 return $this->title;
 }
 public function setTitle($title) {
 $this->title = $title;
 }
 }
  • 17. CREATING / USING THE OBJECT INSTANCE $user = new User();
 $user->setName("Jane Smith");
 $user->setTitle("Ms");
 echo $user->getFormattedSalutation(); When the script is run, it will return: Ms Jane Smith
  • 18. CONSTRUCTOR METHOD & MAGIC METHODS class User {
 protected $name;
 protected $title;
 
 public function __construct($name, $title) {
 $this->name = $name;
 $this->title = $title;
 }
 
 public function __toString() {
 return $this->getFormattedSalutation();
 }
 ...
 } For more see http://php.net/manual/en/language.oop5.magic.php
  • 19. CREATING / USING THE OBJECT INSTANCE $user = new User("Jane Smith","Ms");
 echo $user; When the script is run, it will return the same result as before: Ms Jane Smith
  • 20. INHERITANCE: PASSES KNOWLEDGE DOWN • Subclass, parent and a child relationship, allows for reusability, extensibility. • Additional code to an existing class without modifying it. Uses keyword “extends” • NUTSHELL: create a new class based on an existing class with more data, create new objects based on this class
  • 21. CREATING AND USING A CHILD CLASS class Developer extends User {
 public $skills = array();
 public function getSalutation() {
 return $this->title . " " . $this->name. ", Developer";
 }
 public function getSkillsString() {
 echo implode(", ",$this->skills);
 }
 } $developer = new Developer("Jane Smith", "Ms");
 echo $developer;
 echo "<br />";
 $developer->skills = array("JavasScript", "HTML", "CSS");
 $developer->skills[] = "PHP";
 $developer->getSkillsString();
  • 22. WHEN RUN, THE SCRIPT RETURNS: Ms Jane Smith JavasScript, HTML, CSS, PHP
  • 24. THANK YOU FROM ALENA HOLLIGAN Files at https://github.com/sketchings/oop-basics Contact Info: www.sketchings.com @sketchings alena@holligan.us
  • 25. WELCOME TO ‘INTRO TO OOP WITH PHP’ PART 2 Thank you for your interest. Files can be found at https://github.com/ sketchings/oop-basics Contact Info: www.sketchings.com @sketchings alena@holligan.us
  • 26. INTRO TO OOP WITH PHP (PART 2) A BASIC LOOK INTO OBJECT-ORIENTED PROGRAMMING
  • 27. TERMINOLOGY THE SINGLE MOST IMPORTANT PART
  • 28. TERMS • Class (properties, methods) • Object • Instance • Abstraction • Encapsulation • Inheritance
  • 29. TERMS CONTINUED • Polymorphism • Interface • Abstract • Type Hinting • Namespaces
  • 30. POLYMORPHISM Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface
  • 31. INTERFACE • Interface, specifies which methods a class must implement. • All methods in interface must be public. • Multiple interfaces can be implemented by using comma separation • Interface may contain a CONSTANT, but may not be overridden by implementing class
  • 32. interface UserInterface { public function getFormattedSalutation(); public function getName(); public function setName($name); public function getTitle(); public function setTitle($title); } class User implements UserInterface { … }
  • 33. ABSTRACT An abstract class is a mix between an interface and a class. It can define functionality as well as interface (in the form of abstract methods). Classes extending an abstract class must implement all of the abstract methods defined in the abstract class.
  • 34. abstract class User { //class public $name; //property public getName() { //method echo $this->name; } abstract public function setName($name); } class Developer extends User { … }
  • 35. NAMESPACES • Help create a new layer of code encapsulation • Keep properties from colliding between areas of your code • Only classes, interfaces, functions and constants are affected • Anything that does not have a namespace is considered in the Global namespace (namespace = "")
  • 36. NAMESPACES • must be declared first (except 'declare) • Can define multiple in the same file • You can define that something be used in the "Global" namespace by enclosing a non-labeled namespace in {} brackets. • Use namespaces from within other namespaces, along with aliasing
  • 37. • namespace myUser; • class User { //class • public $name; //property • public getName() { //method • echo $this->name; • } • public function setName($name); • } • class Developer extends myUserUser { … }
  • 39. CHALLENGES 1. Change to User class to an abstract class. 2. Throw an error because your access is too restricted. 3. Extend the User class for another type of user, such as our Developer example 4. Define 2 “User” classes in one file using namespacing
  • 40. THANK YOU FROM ALENA HOLLIGAN I hope you enjoyed this presentation and learned a lot in the short time we had. Please stay tuned for more and fill out the survey to help improve the training. Contact Info: www.sketchings.com @sketchings alena@holligan.us
  • 41. RESOURCES • LeanPub: The essentials of Object Oriented PHP