SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
Object-Oriented Collaboration
PART 1: Terminology
Encapsulation
Abstraction
Polymorphism
Interface
Composition
PART 2: Basic Usage
Anatomy of a Class
properties, methods, “this”
Object
Instance
PART 3: Extending
Inheritance
Interface
Abstract Class
Trait
PART 1: Terminology
Encapsulation
the action of enclosing
something in or as if in a
capsule. Properties
Methods
Abstraction
Decouple usage of from working representations
Removing details in order to more closely attend to other
details of interest
Functions which represent a specific way of
abstracting control flow in programs
Use something without knowing inner workings
How to make a PB&J
Interface
A point where two systems, subjects, organizations,
etc. meet and interact.
The contract for interacting with an object
Polymorphism
The condition of occurring in
several different forms
BIOLOGY
GENETICS
BIOCHEMISTRY
COMPUTING
Shape: Area
QUESTIONS
PART 2: Basic Usage
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.
properties = class variables = data
methods = class functions = actions
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
Identification: Chris
@fideloper
@assertchris
@grmpyprogrammer
@enygma
@crussell52_
@dragonmantank
@chwenz
class User { //class

public $lang = ‘en’; //property

public $name = "Guest"; //property

public $greeting = [

‘en’ => “Welcome”,

‘sp’ => “Hola”,

]; //property

public function getSalutation($lang = null) { //polymorphic method

if (!array_key_exists($lang, $this->greeting)) $lang = $this->lang;

return $this->greeting[$lang] . " " . $this->name; //current

}

}
class User { 

public $lang = ‘en’; //class property

…

public function getSalutation($lang = null) { //polymorphic method

$lang = $this->getLang($lang); //abstracting

return $this->greeting[$lang] . " " . $this->name;

}

public function getLanguage($lang = null) { //reuse

if (!array_key_exists($lang, $this->greeting)) $lang = $this->lang;

return $lang;

}

}
Calling Properties and Methods
$user1 = new User(); //first instance of object

$user2 = new User(); //second instance of object

$user2->name = “alena"; //change property
echo $user1->getSalutation();//method

echo "Hello ".$user2->name;//property

echo $user2->getSalutation(‘sp’);//method
When the script is run, it will return:
Welcome GuestHello alenaHola alena
QUESTIONS
PART 3: Extending
Inheritance
Interface
Abstract Class
Trait
Inheritance: passes knowledge down
Subclass, parent and a child relationship, allows for
reusability, extensibility.
Add code to an existing class without modifying original.
NUTSHELL: create a new class based on an existing
class with more data, create new objects based on this
class
Creating a child class
class Developer extends User {

...

public $greeting = "Hello";//override property

public $skills = array(); //additional property
public function getSkillsString(){ //additional method

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

}
public function getSalutation($lang = null) {//override

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

}

}
Using a child class
$developer = new Developer();

$developer->name = "Ada Lovelace";

echo $developer->getSalutation();
$developer->skills = array("Math", "Algorithms", "Logic");

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

echo $developer->getSkillsString();
When the script is run, it will return:
Hello Ada Lovelace, DeveloperMath, Algorithms, Logic, Countess
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 getSalutation($lang = null);
public function getName();
public function setName($name);
}
class User implements UserInterface { … }
Do I use “Interface” in the name?
class Twilio implements SmsProvider {}
class NexmoSMS implements SmsProviderInterface {}
Doesn't matter either way. Pick a convention and stick with it.
Abstract Class
An abstract class is a mix between an interface and a
class. It can define functionality as well as interface.
Classes extending an abstract class must implement all
of the abstract methods defined in the abstract class.
abstract class User { //abstract class

…

public getName() { //new class method

echo $this->name;

}

abstract public function setName($name);

}
class Developer extends User {

public setName($name) { //implementation

…

}
Trait
Horizontal Code Reuse
Can add as many as you want
Only use for code that you would have to duplicate in non-related classes
that share functionality
Can cause conflicts with overwriting or visibility
Avoid things that operate on properties or methods of specific class
Cannot be use for Type Hinting
Creating Traits
trait Toolkit {

public $tools = array();

public function setTools($task) {

switch ($task) {

case "eat":

$this->tools = 

array("Spoon", "Fork", "Knife");

break;

...

}

}

public function showTools() {

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

}

}
Using Traits
class Developer extends User {

use Toolkit;

...

}
$developer = new Developer();

$developer->setTools("eat");

echo $developer->showTools();
When run the script returns:
Spoon, Fork, Knife
QUESTIONS
Resources
Mastering Object-Oriented PHP by Brandon Savage
LeanPub: The Essentials of Object Oriented PHP
Head First Object-Oriented Analysis and Design
PHP the Right Way
Alena Holligan
• Wife, and Mother of 3 young children
• PHP Teacher at Treehouse
• Portland PHP User Group Leader
• Cascadia PHP Conference (cascadiaphp.com)
@alenaholligan alena@holligan.us https://joind.in/talk/1cd86

Contenu connexe

Tendances

OOP Concepets and UML Class Diagrams
OOP Concepets and UML Class DiagramsOOP Concepets and UML Class Diagrams
OOP Concepets and UML Class DiagramsBhathiya Nuwan
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend classAbhishek Wadhwa
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHPMichael Peacock
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classesasadsardar
 
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
 
Friend functions
Friend functions Friend functions
Friend functions Megha Singh
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Alena Holligan
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasShahzad Younas
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in javaAtul Sehdev
 
Class and Objects in PHP
Class and Objects in PHPClass and Objects in PHP
Class and Objects in PHPRamasubbu .P
 
Seminar on java
Seminar on javaSeminar on java
Seminar on javashathika
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentationtigerwarn
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++Swarup Kumar Boro
 

Tendances (20)

Introduction to php oop
Introduction to php oopIntroduction to php oop
Introduction to php oop
 
OOP Concepets and UML Class Diagrams
OOP Concepets and UML Class DiagramsOOP Concepets and UML Class Diagrams
OOP Concepets and UML Class Diagrams
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend class
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
 
Class diagrams
Class diagramsClass diagrams
Class diagrams
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classes
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
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
 
PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Friend functions
Friend functions Friend functions
Friend functions
 
Inheritance
InheritanceInheritance
Inheritance
 
Class and object
Class and objectClass and object
Class and object
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younas
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
 
Class and Objects in PHP
Class and Objects in PHPClass and Objects in PHP
Class and Objects in PHP
 
Seminar on java
Seminar on javaSeminar on java
Seminar on java
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 

Similaire à Obect-Oriented Collaboration

Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Alena Holligan
 
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
 
Take the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphpTake the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphpAlena Holligan
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
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 - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP[tek] 2017Demystifying Object-Oriented Programming - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP[tek] 2017Alena Holligan
 
Application package
Application packageApplication package
Application packageJAYAARC
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental PrinciplesIntro C# Book
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsMaryo Manjaruni
 
Demystifying Object-Oriented Programming #ssphp16
Demystifying Object-Oriented Programming #ssphp16Demystifying Object-Oriented Programming #ssphp16
Demystifying Object-Oriented Programming #ssphp16Alena Holligan
 
Object Oriented Programming in PHP
Object Oriented Programming  in PHPObject Oriented Programming  in PHP
Object Oriented Programming in PHPwahidullah mudaser
 
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
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5Sayed Ahmed
 

Similaire à Obect-Oriented Collaboration (20)

Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016
 
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
 
Take the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphpTake the Plunge with OOP from #pnwphp
Take the Plunge with OOP from #pnwphp
 
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
 
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 - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP[tek] 2017Demystifying Object-Oriented Programming - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP[tek] 2017
 
Effective PHP. Part 3
Effective PHP. Part 3Effective PHP. Part 3
Effective PHP. Part 3
 
Application package
Application packageApplication package
Application package
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 
Lab 4 (1).pdf
Lab 4 (1).pdfLab 4 (1).pdf
Lab 4 (1).pdf
 
Oops
OopsOops
Oops
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented concepts
 
Demystifying Object-Oriented Programming #ssphp16
Demystifying Object-Oriented Programming #ssphp16Demystifying Object-Oriented Programming #ssphp16
Demystifying Object-Oriented Programming #ssphp16
 
Object Oriented Programming in PHP
Object Oriented Programming  in PHPObject Oriented Programming  in PHP
Object Oriented Programming in PHP
 
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
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5
 

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
 
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
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPress
 
Let's Talk Scope
Let's Talk ScopeLet's Talk Scope
Let's Talk Scope
 
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

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Dernier (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Obect-Oriented Collaboration

  • 3. PART 2: Basic Usage Anatomy of a Class properties, methods, “this” Object Instance
  • 6. Encapsulation the action of enclosing something in or as if in a capsule. Properties Methods
  • 7. Abstraction Decouple usage of from working representations Removing details in order to more closely attend to other details of interest Functions which represent a specific way of abstracting control flow in programs Use something without knowing inner workings
  • 8. How to make a PB&J
  • 9.
  • 10. Interface A point where two systems, subjects, organizations, etc. meet and interact. The contract for interacting with an object
  • 11.
  • 12. Polymorphism The condition of occurring in several different forms BIOLOGY GENETICS BIOCHEMISTRY COMPUTING
  • 14.
  • 15.
  • 16.
  • 18. PART 2: Basic Usage
  • 19. 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. properties = class variables = data methods = class functions = actions
  • 20. 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.
  • 21. 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
  • 23. class User { //class
 public $lang = ‘en’; //property
 public $name = "Guest"; //property
 public $greeting = [
 ‘en’ => “Welcome”,
 ‘sp’ => “Hola”,
 ]; //property
 public function getSalutation($lang = null) { //polymorphic method
 if (!array_key_exists($lang, $this->greeting)) $lang = $this->lang;
 return $this->greeting[$lang] . " " . $this->name; //current
 }
 }
  • 24. class User { 
 public $lang = ‘en’; //class property
 …
 public function getSalutation($lang = null) { //polymorphic method
 $lang = $this->getLang($lang); //abstracting
 return $this->greeting[$lang] . " " . $this->name;
 }
 public function getLanguage($lang = null) { //reuse
 if (!array_key_exists($lang, $this->greeting)) $lang = $this->lang;
 return $lang;
 }
 }
  • 25. Calling Properties and Methods $user1 = new User(); //first instance of object
 $user2 = new User(); //second instance of object
 $user2->name = “alena"; //change property echo $user1->getSalutation();//method
 echo "Hello ".$user2->name;//property
 echo $user2->getSalutation(‘sp’);//method When the script is run, it will return: Welcome GuestHello alenaHola alena
  • 28. Inheritance: passes knowledge down Subclass, parent and a child relationship, allows for reusability, extensibility. Add code to an existing class without modifying original. NUTSHELL: create a new class based on an existing class with more data, create new objects based on this class
  • 29.
  • 30. Creating a child class class Developer extends User {
 ...
 public $greeting = "Hello";//override property
 public $skills = array(); //additional property public function getSkillsString(){ //additional method
 return implode(", ",$this->skills);
 } public function getSalutation($lang = null) {//override
 return $this->greeting." ".$this->name. ", Developer";
 }
 }
  • 31. Using a child class $developer = new Developer();
 $developer->name = "Ada Lovelace";
 echo $developer->getSalutation(); $developer->skills = array("Math", "Algorithms", "Logic");
 $developer->skills[] = "Countess";
 echo $developer->getSkillsString(); When the script is run, it will return: Hello Ada Lovelace, DeveloperMath, Algorithms, Logic, Countess
  • 32. 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
  • 33. interface UserInterface { public function getSalutation($lang = null); public function getName(); public function setName($name); } class User implements UserInterface { … }
  • 34. Do I use “Interface” in the name? class Twilio implements SmsProvider {} class NexmoSMS implements SmsProviderInterface {} Doesn't matter either way. Pick a convention and stick with it.
  • 35. Abstract Class An abstract class is a mix between an interface and a class. It can define functionality as well as interface. Classes extending an abstract class must implement all of the abstract methods defined in the abstract class.
  • 36. abstract class User { //abstract class
 …
 public getName() { //new class method
 echo $this->name;
 }
 abstract public function setName($name);
 } class Developer extends User {
 public setName($name) { //implementation
 …
 }
  • 37. Trait Horizontal Code Reuse Can add as many as you want Only use for code that you would have to duplicate in non-related classes that share functionality Can cause conflicts with overwriting or visibility Avoid things that operate on properties or methods of specific class Cannot be use for Type Hinting
  • 38. Creating Traits trait Toolkit {
 public $tools = array();
 public function setTools($task) {
 switch ($task) {
 case "eat":
 $this->tools = 
 array("Spoon", "Fork", "Knife");
 break;
 ...
 }
 }
 public function showTools() {
 return implode(", ",$this->skills);
 }
 }
  • 39. Using Traits class Developer extends User {
 use Toolkit;
 ...
 } $developer = new Developer();
 $developer->setTools("eat");
 echo $developer->showTools(); When run the script returns: Spoon, Fork, Knife
  • 41. Resources Mastering Object-Oriented PHP by Brandon Savage LeanPub: The Essentials of Object Oriented PHP Head First Object-Oriented Analysis and Design PHP the Right Way
  • 42. Alena Holligan • Wife, and Mother of 3 young children • PHP Teacher at Treehouse • Portland PHP User Group Leader • Cascadia PHP Conference (cascadiaphp.com) @alenaholligan alena@holligan.us https://joind.in/talk/1cd86