SlideShare a Scribd company logo
1 of 15
Download to read offline
AN INTRODUCTION TO
OBJECT-ORIENTED
PROGRAMMING (OOP)
I am , , and .Xano @BartFeenstra http://mynameisbart.com
WHAT IS OBJECT-ORIENTED
PROGRAMMING?
The form of programming that uses instances (objects) of classes
(predefined data types) to structure (group) information and functionality.
GLOSSARY
Class
A predefined type (blueprint) of complex data.
Object
An instance of a class; a single unit of complex data.
Property
A variable that belongs to a class or object.
Method
A function that belongs to a class or object.
STATE
Objects have state (internal configuration) which can be changed.
Most, if not all usages of static variables in Drupal 7 have been replaced with
object properties in Drupal 8.
INTERFACES
Interfaces define what objects must be able to do,
but do not define how they must do these things.
They are contracts that must be fulfilled.
<?php
interface FooInterface {
public function doFoo($foo);
}
interface FooMultipleInterface extends FooInterface {
public function doFooMultiple(array $foos);
}
CLASSES
Classes define what objects must do and how to do this.
In good design, they implement interfaces.
Classes can be instantiated into objects.
<?php
class Foo implements FooInterface {
public function doFoo($foo) {
return sprintf('Hello %s!', $foo);
}
}
$foo = new Foo();
$foo->doFoo('world');
// returns "Hello world!"
ABSTRACT CLASSES
Abstract classes provide partial implementations, but cannot be
instantiated.
<?php
abstract class AbstractFoo implements FooMultipleInterface {
public function doFoo($foo) {
return sprintf('Hello %s!', $foo);
}
}
class Foo extends AbstractFoo implements FooMultipleInterface {
public function doFooMultiple(array $foos) {
$greetings = [];
foreach ($foos as $foo) {
$greetings[] = sprintf('Hello %s!', $foo);
}
return implode(' ', $greetings);
}
}
TRAITS
Traits provide re-usable implementations that can reduce boilerplate code.
Classes can use traits.
<?php
trait FooTrait {
public function doFoo($foo) {
return sprintf('Hello %s!', $foo);
}
}
class Foo implements FooInterface {
use FooTrait;
}
$foo = new Foo();
$foo->doFoo('world');
// returns "Hello world!"
INHERITANCE
Interfaces, traits, and classes can be extended.
Child classes can access methods from their parent classes.
<?php
class Foo implements FooInterface {
public function doFoo($foo) {
return sprintf('Hello %s!', $foo);
}
}
class PoliteFoo extends Foo {
public function doFoo($foo) {
$message = parent::doFoo($foo);
$message .= ' How are you?';
return $message;
}
}
$THIS
$this points to the current object.
<?php
abstract class AbstractFoo implements FooMultipleInterface {
public function doFoo($foo) {
return sprintf('Hello %s!', $foo);
}
}
class Foo extends AbstractFoo implements FooMultipleInterface {
public function doFooMultiple(array $foos) {
$greetings = [];
foreach ($foos as $foo) {
$greetings[] = $this->doFoo($foo);
}
return implode(' ', $greetings);
}
}
VISIBILITY
Developers control which methods can be called from outside the class.
public
Can be called from anywhere.
protected
Can be called only from within the class or any child class.
private
Can only be called from within the same class.
<?php
class Bar {
protected function doBar() {}
}
$bar = new Bar();
$bar->doBar();
// $bar->doBar() causes an error, because we call a protected method from outside the class.
CHECKING AN OBJECT'S TYPE
When accepted as a function parameter (type hinting).
In a block of code (instanceof).
<?php
function foo(FooInterface $foo) {
// Here we only know $foo implements FooInterface.
if ($foo instanceof FooMultipleInterface) {
// Now we know $foo implements FooMultipleInterface too.
}
}
AUTOLOADING USING PSR-4
Industry standard with several available autoloaders.
Class names map to file names.
Namespaces map to directory names.
Much faster and less frustrating than the Drupal 7 registry.
Example: DrupalpaymentEntityPaymentInterfacemaps to
./src/Entity/PaymentInterface.php.
BENEFITS
Classes objects are faster than arrays
( ).
Interfaces and classes are documentation.
IDEs use interfaces and classes for code completion.
Easier and faster coding. Lower chance of bugs.
https://gist.github.com/nikic/5015323
CONCLUSION
OOP MAKES YOU A BETTER DEVELOPER.
Review this presentation at .http://slideshare.net/bartfeenstra
I am , , and .Xano @BartFeenstra http://mynameisbart.com
DO YOU HAVE ANY QUESTIONS?

More Related Content

What's hot

Chapter23 friend-function-friend-class
Chapter23 friend-function-friend-classChapter23 friend-function-friend-class
Chapter23 friend-function-friend-classDeepak Singh
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introductionsandeep54552
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5Sayed Ahmed
 
Inheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismJawad Khan
 
psnreddy php-oops
psnreddy  php-oopspsnreddy  php-oops
psnreddy php-oopssatya552
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend classAbhishek Wadhwa
 
Oop in-php
Oop in-phpOop in-php
Oop in-phpRajesh S
 
Friend functions
Friend functions Friend functions
Friend functions Megha Singh
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHPLorna Mitchell
 
Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperNyros Technologies
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classesasadsardar
 

What's hot (19)

Chapter23 friend-function-friend-class
Chapter23 friend-function-friend-classChapter23 friend-function-friend-class
Chapter23 friend-function-friend-class
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5
 
Inheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphism
 
psnreddy php-oops
psnreddy  php-oopspsnreddy  php-oops
psnreddy php-oops
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
Php oop presentation
Php   oop presentationPhp   oop presentation
Php oop presentation
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Demystifying oop
Demystifying oopDemystifying oop
Demystifying oop
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend class
 
Friend Function
Friend FunctionFriend Function
Friend Function
 
Oop in-php
Oop in-phpOop in-php
Oop in-php
 
Oops in PHP
Oops in PHPOops in PHP
Oops in PHP
 
Friend functions
Friend functions Friend functions
Friend functions
 
Php Oop
Php OopPhp Oop
Php Oop
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
Class and object
Class and objectClass and object
Class and object
 
Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros Developer
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classes
 

Viewers also liked

PHP-FIG: how the PHP world got off their islands (DrupalCamp Vienna 2015)
PHP-FIG: how the PHP world got off their islands (DrupalCamp Vienna 2015)PHP-FIG: how the PHP world got off their islands (DrupalCamp Vienna 2015)
PHP-FIG: how the PHP world got off their islands (DrupalCamp Vienna 2015)Bart Feenstra
 
The Drupal 8 plugin system: extensibility for all (Drupalaton 2015)
The Drupal 8 plugin system: extensibility for all (Drupalaton 2015)The Drupal 8 plugin system: extensibility for all (Drupalaton 2015)
The Drupal 8 plugin system: extensibility for all (Drupalaton 2015)Bart Feenstra
 
The Drupal 8 plugin system: extensibility for all (DrupalCamp Baltics 2015)
The Drupal 8 plugin system: extensibility for all (DrupalCamp Baltics 2015)The Drupal 8 plugin system: extensibility for all (DrupalCamp Baltics 2015)
The Drupal 8 plugin system: extensibility for all (DrupalCamp Baltics 2015)Bart Feenstra
 
Unit 73 ig1 assignment computer game audio cut sequence production 2013_y2
Unit 73 ig1 assignment computer game audio cut sequence production 2013_y2Unit 73 ig1 assignment computer game audio cut sequence production 2013_y2
Unit 73 ig1 assignment computer game audio cut sequence production 2013_y2benstoraro
 
De matias emergencia policial - pase a retiro - imposibilidad del gobernado...
De matias   emergencia policial - pase a retiro - imposibilidad del gobernado...De matias   emergencia policial - pase a retiro - imposibilidad del gobernado...
De matias emergencia policial - pase a retiro - imposibilidad del gobernado...Luis Federico Arias
 
Tp6 - Plan de Medios Online
Tp6 - Plan de Medios OnlineTp6 - Plan de Medios Online
Tp6 - Plan de Medios OnlineGeatwayViajes
 
CHARLIE PREYER.docx resume
CHARLIE PREYER.docx resumeCHARLIE PREYER.docx resume
CHARLIE PREYER.docx resumecharlie preyer
 
Writing news and lead story
Writing news and lead storyWriting news and lead story
Writing news and lead storymediamaryam
 
Presentazione Giulia Covino
Presentazione Giulia CovinoPresentazione Giulia Covino
Presentazione Giulia CovinoLVenture Group
 
20150319 primemobilerealestatesecuringyourplaceonthelockscreen-150320133619-c...
20150319 primemobilerealestatesecuringyourplaceonthelockscreen-150320133619-c...20150319 primemobilerealestatesecuringyourplaceonthelockscreen-150320133619-c...
20150319 primemobilerealestatesecuringyourplaceonthelockscreen-150320133619-c...Dale Sternberg
 
美麗的圖片A
美麗的圖片A美麗的圖片A
美麗的圖片A燿君 吳
 

Viewers also liked (18)

PHP-FIG: how the PHP world got off their islands (DrupalCamp Vienna 2015)
PHP-FIG: how the PHP world got off their islands (DrupalCamp Vienna 2015)PHP-FIG: how the PHP world got off their islands (DrupalCamp Vienna 2015)
PHP-FIG: how the PHP world got off their islands (DrupalCamp Vienna 2015)
 
The Drupal 8 plugin system: extensibility for all (Drupalaton 2015)
The Drupal 8 plugin system: extensibility for all (Drupalaton 2015)The Drupal 8 plugin system: extensibility for all (Drupalaton 2015)
The Drupal 8 plugin system: extensibility for all (Drupalaton 2015)
 
The Drupal 8 plugin system: extensibility for all (DrupalCamp Baltics 2015)
The Drupal 8 plugin system: extensibility for all (DrupalCamp Baltics 2015)The Drupal 8 plugin system: extensibility for all (DrupalCamp Baltics 2015)
The Drupal 8 plugin system: extensibility for all (DrupalCamp Baltics 2015)
 
Unit 73 ig1 assignment computer game audio cut sequence production 2013_y2
Unit 73 ig1 assignment computer game audio cut sequence production 2013_y2Unit 73 ig1 assignment computer game audio cut sequence production 2013_y2
Unit 73 ig1 assignment computer game audio cut sequence production 2013_y2
 
De matias emergencia policial - pase a retiro - imposibilidad del gobernado...
De matias   emergencia policial - pase a retiro - imposibilidad del gobernado...De matias   emergencia policial - pase a retiro - imposibilidad del gobernado...
De matias emergencia policial - pase a retiro - imposibilidad del gobernado...
 
Tp6 - Plan de Medios Online
Tp6 - Plan de Medios OnlineTp6 - Plan de Medios Online
Tp6 - Plan de Medios Online
 
CHARLIE PREYER.docx resume
CHARLIE PREYER.docx resumeCHARLIE PREYER.docx resume
CHARLIE PREYER.docx resume
 
SEMcamp 5 savchishin semcamp2013-ruslan-alternatives-to-seo
SEMcamp 5 savchishin semcamp2013-ruslan-alternatives-to-seoSEMcamp 5 savchishin semcamp2013-ruslan-alternatives-to-seo
SEMcamp 5 savchishin semcamp2013-ruslan-alternatives-to-seo
 
Inversión total y estructura financiera
Inversión total y estructura financieraInversión total y estructura financiera
Inversión total y estructura financiera
 
簡報1
簡報1簡報1
簡報1
 
Writing news and lead story
Writing news and lead storyWriting news and lead story
Writing news and lead story
 
Presentazione Giulia Covino
Presentazione Giulia CovinoPresentazione Giulia Covino
Presentazione Giulia Covino
 
簡報1
簡報1簡報1
簡報1
 
20150319 primemobilerealestatesecuringyourplaceonthelockscreen-150320133619-c...
20150319 primemobilerealestatesecuringyourplaceonthelockscreen-150320133619-c...20150319 primemobilerealestatesecuringyourplaceonthelockscreen-150320133619-c...
20150319 primemobilerealestatesecuringyourplaceonthelockscreen-150320133619-c...
 
UNDERGRADUATE COURSE DESCRIPTIONS
UNDERGRADUATE COURSE DESCRIPTIONSUNDERGRADUATE COURSE DESCRIPTIONS
UNDERGRADUATE COURSE DESCRIPTIONS
 
美麗的圖片A
美麗的圖片A美麗的圖片A
美麗的圖片A
 
Pracmatics
PracmaticsPracmatics
Pracmatics
 
Formulir pengajuan Small Grant Activity PWYP Indonesia
Formulir pengajuan Small Grant Activity PWYP  IndonesiaFormulir pengajuan Small Grant Activity PWYP  Indonesia
Formulir pengajuan Small Grant Activity PWYP Indonesia
 

Similar to An Introduction to Object-Oriented Programming (DrupalCamp Leuven 2015)

Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Alena Holligan
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5Jason Austin
 
Objects, Testing, and Responsibility
Objects, Testing, and ResponsibilityObjects, Testing, and Responsibility
Objects, Testing, and Responsibilitymachuga
 
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
 
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
 
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
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Alena Holligan
 
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
 
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
 
PHP OOP Lecture - 04.pptx
PHP OOP Lecture - 04.pptxPHP OOP Lecture - 04.pptx
PHP OOP Lecture - 04.pptxAtikur Rahman
 

Similar to An Introduction to Object-Oriented Programming (DrupalCamp Leuven 2015) (20)

Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016
 
OOP
OOPOOP
OOP
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5
 
Objects, Testing, and Responsibility
Objects, Testing, and ResponsibilityObjects, Testing, and Responsibility
Objects, Testing, and Responsibility
 
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
 
OOP in PHP
OOP in PHPOOP in PHP
OOP 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
 
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
 
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
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
Design attern in php
Design attern in phpDesign attern in php
Design attern in php
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18
 
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
 
Intro to OOP PHP and Github
Intro to OOP PHP and GithubIntro to OOP PHP and Github
Intro to OOP PHP and Github
 
PHP OOP Lecture - 04.pptx
PHP OOP Lecture - 04.pptxPHP OOP Lecture - 04.pptx
PHP OOP Lecture - 04.pptx
 

Recently uploaded

Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftAanSulistiyo
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...roncy bisnoi
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...singhpriety023
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...tanu pandey
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...SUHANI PANDEY
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdfMatthew Sinclair
 
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...nirzagarg
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubaikojalkojal131
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...SUHANI PANDEY
 
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋nirzagarg
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrHenryBriggs2
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋nirzagarg
 
Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...
Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...
Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...SUHANI PANDEY
 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...SUHANI PANDEY
 

Recently uploaded (20)

📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
 
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...
Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...
Wadgaon Sheri $ Call Girls Pune 10k @ I'm VIP Independent Escorts Girls 80057...
 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
 

An Introduction to Object-Oriented Programming (DrupalCamp Leuven 2015)

  • 1. AN INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) I am , , and .Xano @BartFeenstra http://mynameisbart.com
  • 2. WHAT IS OBJECT-ORIENTED PROGRAMMING? The form of programming that uses instances (objects) of classes (predefined data types) to structure (group) information and functionality.
  • 3. GLOSSARY Class A predefined type (blueprint) of complex data. Object An instance of a class; a single unit of complex data. Property A variable that belongs to a class or object. Method A function that belongs to a class or object.
  • 4. STATE Objects have state (internal configuration) which can be changed. Most, if not all usages of static variables in Drupal 7 have been replaced with object properties in Drupal 8.
  • 5. INTERFACES Interfaces define what objects must be able to do, but do not define how they must do these things. They are contracts that must be fulfilled. <?php interface FooInterface { public function doFoo($foo); } interface FooMultipleInterface extends FooInterface { public function doFooMultiple(array $foos); }
  • 6. CLASSES Classes define what objects must do and how to do this. In good design, they implement interfaces. Classes can be instantiated into objects. <?php class Foo implements FooInterface { public function doFoo($foo) { return sprintf('Hello %s!', $foo); } } $foo = new Foo(); $foo->doFoo('world'); // returns "Hello world!"
  • 7. ABSTRACT CLASSES Abstract classes provide partial implementations, but cannot be instantiated. <?php abstract class AbstractFoo implements FooMultipleInterface { public function doFoo($foo) { return sprintf('Hello %s!', $foo); } } class Foo extends AbstractFoo implements FooMultipleInterface { public function doFooMultiple(array $foos) { $greetings = []; foreach ($foos as $foo) { $greetings[] = sprintf('Hello %s!', $foo); } return implode(' ', $greetings); } }
  • 8. TRAITS Traits provide re-usable implementations that can reduce boilerplate code. Classes can use traits. <?php trait FooTrait { public function doFoo($foo) { return sprintf('Hello %s!', $foo); } } class Foo implements FooInterface { use FooTrait; } $foo = new Foo(); $foo->doFoo('world'); // returns "Hello world!"
  • 9. INHERITANCE Interfaces, traits, and classes can be extended. Child classes can access methods from their parent classes. <?php class Foo implements FooInterface { public function doFoo($foo) { return sprintf('Hello %s!', $foo); } } class PoliteFoo extends Foo { public function doFoo($foo) { $message = parent::doFoo($foo); $message .= ' How are you?'; return $message; } }
  • 10. $THIS $this points to the current object. <?php abstract class AbstractFoo implements FooMultipleInterface { public function doFoo($foo) { return sprintf('Hello %s!', $foo); } } class Foo extends AbstractFoo implements FooMultipleInterface { public function doFooMultiple(array $foos) { $greetings = []; foreach ($foos as $foo) { $greetings[] = $this->doFoo($foo); } return implode(' ', $greetings); } }
  • 11. VISIBILITY Developers control which methods can be called from outside the class. public Can be called from anywhere. protected Can be called only from within the class or any child class. private Can only be called from within the same class. <?php class Bar { protected function doBar() {} } $bar = new Bar(); $bar->doBar(); // $bar->doBar() causes an error, because we call a protected method from outside the class.
  • 12. CHECKING AN OBJECT'S TYPE When accepted as a function parameter (type hinting). In a block of code (instanceof). <?php function foo(FooInterface $foo) { // Here we only know $foo implements FooInterface. if ($foo instanceof FooMultipleInterface) { // Now we know $foo implements FooMultipleInterface too. } }
  • 13. AUTOLOADING USING PSR-4 Industry standard with several available autoloaders. Class names map to file names. Namespaces map to directory names. Much faster and less frustrating than the Drupal 7 registry. Example: DrupalpaymentEntityPaymentInterfacemaps to ./src/Entity/PaymentInterface.php.
  • 14. BENEFITS Classes objects are faster than arrays ( ). Interfaces and classes are documentation. IDEs use interfaces and classes for code completion. Easier and faster coding. Lower chance of bugs. https://gist.github.com/nikic/5015323
  • 15. CONCLUSION OOP MAKES YOU A BETTER DEVELOPER. Review this presentation at .http://slideshare.net/bartfeenstra I am , , and .Xano @BartFeenstra http://mynameisbart.com DO YOU HAVE ANY QUESTIONS?