SlideShare a Scribd company logo
1 of 55
Download to read offline
OOP is More Than Cats
and Dogs
Chris	
  Tankersley	
  
LonestarPHP	
  2015	
  
LonestarPHP	
  2015	
   1	
  
Who Am I
•  PHP	
  Programmer	
  for	
  over	
  10	
  years	
  
•  Work/know	
  a	
  lot	
  of	
  different	
  
languages,	
  even	
  COBOL	
  
•  Primarily	
  do	
  Zend	
  Framework	
  2	
  
•  hFps://github.com/dragonmantank	
  
LonestarPHP	
  2015	
   2	
  
Quick Vocabulary Lesson
•  Class	
  –	
  DefiniOon	
  of	
  code	
  
•  Object	
  –	
  InstanOaOon	
  of	
  a	
  Class	
  
•  Member	
  –	
  Variable	
  belonging	
  to	
  a	
  class	
  
•  Method	
  –	
  FuncOon	
  belonging	
  to	
  a	
  class	
  
There	
  will	
  be	
  more	
  as	
  we	
  go	
  along	
  
LonestarPHP	
  2015	
   3	
  
LonestarPHP	
  2015	
   4	
  
Class
class Employee {
protected $name; // This is a member
protected $number;
// This is a Method
public function setData($data) {
$this->name = $data['name'];
$this->number = $data['number'];
}
public function viewData() {
echo <<<ENDTEXT
Name: {$this->name}
Number: {$this->number}
ENDTEXT;
}
}
Object
•  <?php!
•  $manager= new Manager();!
•  // ^!
•  // |!
•  // `--- This is the Object	
  
LonestarPHP	
  2015	
   5	
  
Why are we using OOP?
LonestarPHP	
  2015	
   6	
  
Let’s count the reasons
•  Because	
  we’re	
  told	
  to,	
  procedural	
  programming	
  leads	
  to	
  spagheX	
  
code	
  
•  We	
  deal	
  with	
  objects	
  every	
  day,	
  so	
  it	
  shouldn’t	
  be	
  too	
  hard	
  
•  We	
  want	
  to	
  allow	
  for	
  code	
  re-­‐use	
  
•  We	
  want	
  to	
  group	
  like	
  code	
  together	
  
•  We	
  want	
  to	
  easily	
  extend	
  our	
  code	
  
•  We	
  want	
  to	
  be	
  able	
  to	
  easily	
  test	
  our	
  code	
  
LonestarPHP	
  2015	
   7	
  
Getting OOP Right can be Complicated
•  Animals	
  can	
  speak,	
  and	
  have	
  legs	
  and	
  fur.	
  Let’s	
  make	
  objects	
  based	
  
on	
  that	
  
•  Dogs	
  are	
  animals,	
  and	
  so	
  are	
  cats	
  
•  What	
  about	
  Fish?	
  
•  Cars	
  have	
  doors,	
  engines,	
  and	
  colors.	
  They	
  only	
  go	
  so	
  fast.	
  Let’s	
  
model	
  that	
  
•  Motorcycles	
  aren’t	
  Cars,	
  so	
  let’s	
  refactor	
  Cars	
  
•  Holy	
  crap	
  there	
  are	
  a	
  lot	
  of	
  engines…	
  and	
  wheels…	
  	
  
LonestarPHP	
  2015	
   8	
  
Can a Dog have Wheels?
•  Discuss	
  (or	
  listen	
  to	
  me	
  talk	
  some	
  more)	
  
LonestarPHP	
  2015	
   9	
  
Inheritance
LonestarPHP	
  2015	
   10	
  
What we’re all taught
•  Classes	
  are	
  “things”	
  in	
  the	
  real	
  world	
  
•  We	
  should	
  construct	
  class	
  members	
  based	
  on	
  AFributes	
  
•  Number	
  of	
  wheels	
  
•  Sound	
  it	
  makes	
  
•  We	
  should	
  construct	
  class	
  methods	
  based	
  on	
  “AcOons”	
  
•  Running	
  
•  Speaking	
  
•  Jumping	
  
LonestarPHP	
  2015	
   11	
  
New Vocabulary
•  Parent	
  Class	
  –	
  Class	
  that	
  is	
  extended	
  
•  Child	
  Class	
  –	
  Class	
  that	
  is	
  extending	
  another	
  class	
  
In	
  PHP,	
  a	
  class	
  can	
  be	
  both	
  a	
  Child	
  and	
  a	
  Parent	
  at	
  the	
  same	
  Ome	
  
LonestarPHP	
  2015	
   12	
  
Where I Learned It
LonestarPHP	
  2015	
   13	
  
Our Structure
LonestarPHP	
  2015	
   14	
  
Employee	
  
Manager	
   ScienOst	
   Laborer	
  
The Employee Class
LonestarPHP	
  2015	
   15	
  
abstract class Employee {
protected $name; // Employee Name
protected $number; // Employee Number
public function setData($data) {
$this->name = $data['name'];
$this->number = $data['number'];
}
public function viewData() {
echo <<<ENDTEXT
Name: {$this->name}
Number: {$this->number}
ENDTEXT;
}
}
The Manager Class
LonestarPHP	
  2015	
   16	
  
class Manager extends Employee {
protected $title; // Employee Title
protected $dues; // Golf Dues
public function setData($data) {
parent::setData($data);
$this->title = $data['title'];
$this->dues = $data['dues'];
}
public function viewData() {
parent::viewData();
echo <<<ENDTEXT
Title: {$this->title}
Golf Dues: {$this->dues}
ENDTEXT;
}
}
The Scientist Class
LonestarPHP	
  2015	
   17	
  
class Scientist extends Employee {
protected $pubs; // Number of Publications
public function setData($data) {
parent::setData($data);
$this->pubs = $data['pubs'];
}
public function viewData() {
parent::viewData();
echo <<<ENDTEXT
Publications: {$this->pubs}
ENDTEXT;
}
}
The Laborer Class
LonestarPHP	
  2015	
   18	
  
class Laborer extends Employee {
}
What does this teach us?
•  Inheritance	
  
•  Makes	
  it	
  easier	
  to	
  group	
  code	
  together	
  and	
  share	
  it	
  amongst	
  classes	
  
•  Allows	
  us	
  to	
  extend	
  code	
  as	
  needed	
  
•  PHP	
  allows	
  Single	
  inheritance	
  
LonestarPHP	
  2015	
   19	
  
We use it all the time
namespace ApplicationController;!
!
use ZendMvcControllerAbstractActionController;!
use ZendViewModelViewModel;!
!
Class IndexController extends AbstractActionController!
{!
public function indexAction()!
{!
/** @var VendorVendorService $vendor */!
$vendor = $this->serviceLocator->get('VendorVendorService');!
!
$view = new ViewModel();!
return $view;!
}!
}	
  
LonestarPHP	
  2015	
   20	
  
Why it Works (Most of the time, Kinda)
•  Allows	
  us	
  to	
  extend	
  things	
  we	
  didn’t	
  necessarily	
  create	
  
•  Encourages	
  code	
  re-­‐use	
  
•  Allows	
  developers	
  to	
  abstract	
  away	
  things	
  
LonestarPHP	
  2015	
   21	
  
How to use it
•  Understand	
  the	
  difference	
  between	
  Public,	
  Protected,	
  and	
  Private	
  
•  Public	
  –	
  Anyone	
  can	
  use	
  this,	
  even	
  children	
  
•  Protected	
  –	
  Anything	
  internal	
  can	
  use	
  this,	
  even	
  children	
  
•  Private	
  –	
  This	
  is	
  mine,	
  hands	
  off	
  
•  Abstract	
  vs	
  Concrete	
  Classes	
  
•  Abstract	
  classes	
  cannot	
  be	
  instanOated	
  directly,	
  they	
  must	
  be	
  extended	
  
LonestarPHP	
  2015	
   22	
  
The Employee Class
LonestarPHP	
  2015	
   23	
  
abstract class Employee {
protected $name; // Employee Name
protected $number; // Employee Number
public function setData($data) {
$this->name = $data['name'];
$this->number = $data['number'];
}
public function viewData() {
echo <<<ENDTEXT
Name: {$this->name}
Number: {$this->number}
ENDTEXT;
}
}
The Manager Class
LonestarPHP	
  2015	
   24	
  
class Manager extends Employee {
protected $title; // Employee Title
protected $dues; // Golf Dues
public function setData($data) {
parent::setData($data);
$this->title = $data['title'];
$this->dues = $data['dues'];
}
public function viewData() {
parent::viewData();
echo <<<ENDTEXT
Title: {$this->title}
Golf Dues: {$this->dues}
ENDTEXT;
}
}
An Example
<?php!
// Cannot do this. This will throw the following error:!
// Fatal error: Cannot instantiate abstract class Employee!
$employee = new Employee(); !
// We can do this though!!
$manager = new Manager(); !
// Name is protected, so we can't do this. This throws:!
// Fatal error: Cannot access protected property Manager::$name!
$manager->name = 'Bob McManager’;!
// setData is public, so we can use that!
$manager->setData(['name' => 'Bob McManager’,'number' => 1]);!
// We can also view the data, since it's public!
$manager->viewData();	
  
LonestarPHP	
  2015	
   25	
  
Why can Inheritance Be Bad
•  PHP	
  only	
  allows	
  Single	
  Inheritance	
  on	
  an	
  Class	
  
•  You	
  can	
  have	
  a	
  series	
  of	
  Inheritance	
  though,	
  for	
  example	
  CEO	
  extends	
  
Manager,	
  Manager	
  extends	
  Employee	
  
•  Long	
  inheritance	
  chains	
  can	
  be	
  a	
  code	
  smell	
  
•  Private	
  members	
  and	
  methods	
  cannot	
  be	
  used	
  by	
  Child	
  classes	
  
•  Single	
  Inheritance	
  can	
  make	
  it	
  hard	
  to	
  ‘bolt	
  on’	
  new	
  funcOonality	
  
between	
  disparate	
  classes	
  
LonestarPHP	
  2015	
   26	
  
Composition over Inheritance
LonestarPHP	
  2015	
   27	
  
The General Idea
•  Classes	
  contain	
  other	
  classes	
  to	
  do	
  work	
  and	
  extend	
  that	
  way,	
  instead	
  
of	
  through	
  Inheritance	
  
•  Interfaces	
  define	
  “contracts”	
  that	
  objects	
  will	
  adhere	
  to	
  
•  Your	
  classes	
  implement	
  interfaces	
  to	
  add	
  needed	
  funcOonality	
  
LonestarPHP	
  2015	
   28	
  
Interfaces
interface EmployeeInterface {!
protected $name;!
protected $number;!
!
public function getName();!
public function setName($name);!
public function getNumber();!
public function setNumber($number);!
}!
!
interface ManagerInterface {!
protected $golfHandicap;!
!
public function getHandicap();!
public function setHandicap($handicap);!
}	
  
LonestarPHP	
  2015	
   29	
  
Interface Implementation
class Employee implements EmployeeInterface {!
public function getName() {!
return $this->name;!
}!
public function setName($name) {!
$this->name = $name;!
}!
}!
class Manager implements EmployeeInterface, ManagerInterface {!
// defines the employee getters/setters as well!
public function getHandicap() {!
return $this->handicap; !
}!
public function setHandicap($handicap) {!
$this->handicap = $handicap;!
}!
}	
  
LonestarPHP	
  2015	
   30	
  
This is Good and Bad
•  “HAS-­‐A”	
  is	
  tends	
  to	
  be	
  more	
  flexible	
  than	
  “IS-­‐A”	
  
•  Somewhat	
  easier	
  to	
  understand,	
  since	
  there	
  isn’t	
  a	
  hierarchy	
  you	
  
have	
  to	
  backtrack	
  	
  
•  Each	
  class	
  must	
  provide	
  their	
  own	
  ImplementaOon,	
  so	
  can	
  lead	
  to	
  
code	
  duplicaOon	
  
LonestarPHP	
  2015	
   31	
  
Traits
•  Allows	
  small	
  blocks	
  of	
  code	
  to	
  be	
  defined	
  that	
  can	
  be	
  used	
  by	
  many	
  
classes	
  
•  Useful	
  when	
  abstract	
  classes/inheritance	
  would	
  be	
  cumbersome	
  
•  My	
  Posts	
  and	
  Pages	
  classes	
  should	
  need	
  to	
  extend	
  a	
  Slugger	
  class	
  just	
  to	
  
generate	
  slugs.	
  	
  
LonestarPHP	
  2015	
   32	
  
Avoid Code-Duplication with Traits
trait EmployeeTrait {!
public function getName() {!
return $this->name;!
}!
public function setName($name) {!
$this->name = $name;!
}!
}!
class Employee implements EmployeeInterface {!
use EmployeeTrait;!
}!
class Manager implements EmployeeInterface, ManagerInterface {!
use EmployeeTrait;!
use ManagerTrait;!
}	
  
LonestarPHP	
  2015	
   33	
  
Taking Advantage of OOP
LonestarPHP	
  2015	
   34	
  
Coupling
LonestarPHP	
  2015	
   35	
  
What is Coupling?
•  Coupling	
  is	
  how	
  dependent	
  your	
  code	
  is	
  on	
  another	
  class	
  
•  The	
  more	
  classes	
  you	
  are	
  coupled	
  to,	
  the	
  more	
  changes	
  affect	
  your	
  
class	
  
LonestarPHP	
  2015	
   36	
  
<?php!
!
namespace ApplicationController;!
!
use ZendMvcControllerAbstractActionController;!
use ZendViewModelViewModel;!
!
class MapController extends AbstractActionController!
{!
public function indexAction()!
{!
// Position is an array with a Latitude and Longitude object!
$position = $this->getServiceLocator()->get('MapService’)!
->getLatLong('123 Main Street', 'Defiance', 'OH');!
echo $position->latitude->getPoint();!
}!
}	
  
LonestarPHP	
  2015	
   37	
  
Law of Demeter
LonestarPHP	
  2015	
   38	
  
Dependency Injection
LonestarPHP	
  2015	
   39	
  
What is Dependency Injection?
•  InjecOng	
  dependencies	
  into	
  classes,	
  instead	
  of	
  having	
  the	
  class	
  create	
  
it	
  
•  Allows	
  for	
  much	
  easier	
  tesOng	
  
•  Allows	
  for	
  a	
  much	
  easier	
  Ome	
  swapping	
  out	
  code	
  
•  Reduces	
  the	
  coupling	
  that	
  happens	
  between	
  classes	
  
LonestarPHP	
  2015	
   40	
  
Method Injection
class MapService {!
public function getLatLong(GoogleMaps $map, $street, $city, $state) {!
return $map->getLatLong($street . ' ' . $city . ' ' . $state);!
}!
!
public function getAddress(GoogleMaps $map, $lat, $long) {!
return $map->getAddress($lat, $long);!
}!
}	
  
LonestarPHP	
  2015	
   41	
  
Constructor Injection
class MapService {!
protected $map;!
public function __construct(GoogleMaps $map) {!
$this->map = $map;!
}!
public function getLatLong($street, $city, $state) {!
return $this!
->map!
->getLatLong($street . ' ' . $city . ' ' . $state);!
}!
}!
!
	
  
LonestarPHP	
  2015	
   42	
  
Setter Injection
class MapService {!
protected $map;!
!
public function setMap(GoogleMaps $map) {!
$this->map = $map;!
}!
public function getMap() {!
return $this->map;!
}!
public function getLatLong($street, $city, $state) {!
return $this->getMap()->getLatLong($street . ' ' . $city . ' ' . $state);!
}!
}!
	
  
LonestarPHP	
  2015	
   43	
  
Single Responsibility Principle
LonestarPHP	
  2015	
   44	
  
Single Responsibility Principle
•  Every	
  class	
  should	
  have	
  a	
  single	
  responsibility,	
  and	
  that	
  responsibility	
  
should	
  be	
  encapsulated	
  in	
  that	
  class	
  
LonestarPHP	
  2015	
   45	
  
What is a Responsibility?
•  Responsibility	
  is	
  a	
  “Reason	
  To	
  Change”	
  –	
  Robert	
  C.	
  MarOn	
  
•  By	
  having	
  more	
  than	
  one	
  “Reason	
  to	
  Change”,	
  code	
  is	
  harder	
  to	
  
maintain	
  and	
  becomes	
  coupled	
  
•  Since	
  the	
  class	
  is	
  coupled	
  to	
  mulOple	
  responsibiliOes,	
  it	
  becomes	
  
harder	
  for	
  the	
  class	
  to	
  adapt	
  to	
  any	
  one	
  responsibility	
  
	
  
LonestarPHP	
  2015	
   46	
  
An Example
/**
* Create a new invoice instance.
*
* @param LaravelCashierContractsBillable $billable
* @param object
* @return void
*/
public function __construct(BillableContract $billable, $invoice)
{
$this->billable = $billable;
$this->files = new Filesystem;
$this->stripeInvoice = $invoice;
}
/**
* Create an invoice download response.
*
* @param array $data
* @param string $storagePath
* @return SymfonyComponentHttpFoundationResponse
*/
public function download(array $data, $storagePath = null)
{
$filename = $this->getDownloadFilename($data['product']);
$document = $this->writeInvoice($data, $storagePath);
$response = new Response($this->files->get($document), 200, [
'Content-Description' => 'File Transfer',
'Content-Disposition' => 'attachment; filename="'.$filename.'"',
'Content-Transfer-Encoding' => 'binary',
'Content-Type' => 'application/pdf',
]);
$this->files->delete($document);
return $response;
}
LonestarPHP	
  2015	
   47	
  
hFps://github.com/laravel/cashier/blob/master/src/Laravel/Cashier/Invoice.php	
  
Why is this Bad?
•  This	
  single	
  class	
  has	
  the	
  following	
  responsibiliOes:	
  
•  GeneraOng	
  totals	
  for	
  the	
  invoice	
  (including	
  discounts/coupons)	
  
•  GeneraOng	
  an	
  HTML	
  View	
  of	
  the	
  invoice	
  (Invoice::view())	
  
•  GeneraOng	
  a	
  PDF	
  download	
  of	
  the	
  invoice(Invoice::download())	
  
•  This	
  is	
  coupled	
  to	
  a	
  shell	
  script	
  as	
  well	
  
•  Two	
  different	
  displays	
  handled	
  by	
  the	
  class.	
  Adding	
  more	
  means	
  
more	
  responsibility	
  
•  Coupled	
  to	
  a	
  specific	
  HTML	
  template,	
  the	
  filesystem,	
  the	
  Laravel	
  
Views	
  system,	
  and	
  PhantomJS	
  via	
  the	
  shell	
  script	
  
LonestarPHP	
  2015	
   48	
  
How to Improve
•  Change	
  responsibility	
  to	
  just	
  building	
  the	
  invoice	
  data	
  
•  Move	
  the	
  ‘output’	
  stuff	
  to	
  other	
  classes	
  
LonestarPHP	
  2015	
   49	
  
Unit Testing
LonestarPHP	
  2015	
   50	
  
This is not a testing talk
•  Using	
  Interfaces	
  makes	
  it	
  easier	
  to	
  mock	
  objects	
  
•  Reducing	
  coupling	
  and	
  following	
  Demeter’s	
  Law	
  makes	
  you	
  have	
  to	
  
mock	
  less	
  objects	
  
•  Dependency	
  InjecOon	
  means	
  you	
  only	
  mock	
  what	
  you	
  need	
  for	
  that	
  
test	
  
•  Single	
  Responsibility	
  means	
  your	
  test	
  should	
  be	
  short	
  and	
  sweet	
  
•  Easier	
  tesOng	
  leads	
  to	
  more	
  tesOng	
  
LonestarPHP	
  2015	
   51	
  
Final Thoughts
LonestarPHP	
  2015	
   52	
  
We can make a dog with wheels!
•  Abstract	
  class	
  for	
  Animal	
  
•  Class	
  for	
  Dog	
  that	
  extends	
  Animal	
  
•  Trait	
  for	
  Wheels	
  
•  With	
  the	
  write	
  methodology,	
  we	
  could	
  even	
  unit	
  test	
  this	
  
In	
  the	
  real	
  world,	
  we	
  can	
  now	
  represent	
  a	
  crippled	
  dog	
  
LonestarPHP	
  2015	
   53	
  
Here’s a cute dog instead
LonestarPHP	
  2015	
   54	
  
Thank You!
hFp://ctankersley.com	
  
chris@ctankersley.com	
  
@dragonmantank	
  
	
  
hFps://joind.in/13542	
  
LonestarPHP	
  2015	
   55	
  

More Related Content

What's hot

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
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Developmentjsmith92
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database ProgrammingAhmed Swilam
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Nikita Popov
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?Nikita Popov
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016Britta Alex
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Nikita Popov
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Nikita Popov
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021Ayesh Karunaratne
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & ArraysHenry Osborne
 
Php 7 errors messages
Php 7 errors messagesPhp 7 errors messages
Php 7 errors messagesDamien Seguy
 
Php Chapter 2 3 Training
Php Chapter 2 3 TrainingPhp Chapter 2 3 Training
Php Chapter 2 3 TrainingChris Chubb
 

What's hot (20)

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
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
 
Cfphp Zce 01 Basics
Cfphp Zce 01 BasicsCfphp Zce 01 Basics
Cfphp Zce 01 Basics
 
OOP
OOPOOP
OOP
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Php + my sql
Php + my sqlPhp + my sql
Php + my sql
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Php 7 errors messages
Php 7 errors messagesPhp 7 errors messages
Php 7 errors messages
 
Developing SOLID Code
Developing SOLID CodeDeveloping SOLID Code
Developing SOLID Code
 
Php Chapter 2 3 Training
Php Chapter 2 3 TrainingPhp Chapter 2 3 Training
Php Chapter 2 3 Training
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 

Similar to OOP is More Than Just Animals

Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Chris Tankersley
 
OOP Is More Then Cars and Dogs - Midwest PHP 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017OOP Is More Then Cars and Dogs - Midwest PHP 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017Chris Tankersley
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)Krzysztof Menżyk
 
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof MenżykPROIDEA
 
02 - Second meetup
02 - Second meetup02 - Second meetup
02 - Second meetupEdiPHP
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Stephan Schmidt
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricksFilip Golonka
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
PHP OOP Lecture - 02.pptx
PHP OOP Lecture - 02.pptxPHP OOP Lecture - 02.pptx
PHP OOP Lecture - 02.pptxAtikur Rahman
 
Object Oriented Programming for WordPress Plugin Development
Object Oriented Programming for WordPress Plugin DevelopmentObject Oriented Programming for WordPress Plugin Development
Object Oriented Programming for WordPress Plugin Developmentmtoppa
 
Objects, Testing, and Responsibility
Objects, Testing, and ResponsibilityObjects, Testing, and Responsibility
Objects, Testing, and Responsibilitymachuga
 
DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)Oleg Zinchenko
 

Similar to OOP is More Than Just Animals (20)

Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016
 
OOP Is More Then Cars and Dogs - Midwest PHP 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017OOP Is More Then Cars and Dogs - Midwest PHP 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
 
Modern php
Modern phpModern php
Modern php
 
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
 
Be pragmatic, be SOLID
Be pragmatic, be SOLIDBe pragmatic, be SOLID
Be pragmatic, be SOLID
 
02 - Second meetup
02 - Second meetup02 - Second meetup
02 - Second meetup
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
 
Further Php
Further PhpFurther Php
Further Php
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricks
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Starting Out With PHP
Starting Out With PHPStarting Out With PHP
Starting Out With PHP
 
PHP OOP Lecture - 02.pptx
PHP OOP Lecture - 02.pptxPHP OOP Lecture - 02.pptx
PHP OOP Lecture - 02.pptx
 
Object Oriented Programming for WordPress Plugin Development
Object Oriented Programming for WordPress Plugin DevelopmentObject Oriented Programming for WordPress Plugin Development
Object Oriented Programming for WordPress Plugin Development
 
Objects, Testing, and Responsibility
Objects, Testing, and ResponsibilityObjects, Testing, and Responsibility
Objects, Testing, and Responsibility
 
DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)
 

More from Chris Tankersley

Docker is Dead: Long Live Containers
Docker is Dead: Long Live ContainersDocker is Dead: Long Live Containers
Docker is Dead: Long Live ContainersChris Tankersley
 
Bend time to your will with git
Bend time to your will with gitBend time to your will with git
Bend time to your will with gitChris Tankersley
 
Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)Chris Tankersley
 
Dead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIDead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIChris Tankersley
 
Killer Docker Workflows for Development
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for DevelopmentChris Tankersley
 
Docker for Developers - PHP Detroit 2018
Docker for Developers - PHP Detroit 2018Docker for Developers - PHP Detroit 2018
Docker for Developers - PHP Detroit 2018Chris Tankersley
 
BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018Chris Tankersley
 
You Were Lied To About Optimization
You Were Lied To About OptimizationYou Were Lied To About Optimization
You Were Lied To About OptimizationChris Tankersley
 
Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017Chris Tankersley
 
Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017Chris Tankersley
 
Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Chris Tankersley
 
Why Docker? Dayton PHP, April 2017
Why Docker? Dayton PHP, April 2017Why Docker? Dayton PHP, April 2017
Why Docker? Dayton PHP, April 2017Chris Tankersley
 
From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017Chris Tankersley
 
Docker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPDocker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPChris Tankersley
 
How We Got Here: A Brief History of Open Source
How We Got Here: A Brief History of Open SourceHow We Got Here: A Brief History of Open Source
How We Got Here: A Brief History of Open SourceChris Tankersley
 
Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016Chris Tankersley
 
From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016Chris Tankersley
 

More from Chris Tankersley (20)

Docker is Dead: Long Live Containers
Docker is Dead: Long Live ContainersDocker is Dead: Long Live Containers
Docker is Dead: Long Live Containers
 
Bend time to your will with git
Bend time to your will with gitBend time to your will with git
Bend time to your will with git
 
Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)
 
Dead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIDead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPI
 
Killer Docker Workflows for Development
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for Development
 
You Got Async in my PHP!
You Got Async in my PHP!You Got Async in my PHP!
You Got Async in my PHP!
 
Docker for Developers - PHP Detroit 2018
Docker for Developers - PHP Detroit 2018Docker for Developers - PHP Detroit 2018
Docker for Developers - PHP Detroit 2018
 
Docker for Developers
Docker for DevelopersDocker for Developers
Docker for Developers
 
They are Watching You
They are Watching YouThey are Watching You
They are Watching You
 
BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018
 
You Were Lied To About Optimization
You Were Lied To About OptimizationYou Were Lied To About Optimization
You Were Lied To About Optimization
 
Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017
 
Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017
 
Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017
 
Why Docker? Dayton PHP, April 2017
Why Docker? Dayton PHP, April 2017Why Docker? Dayton PHP, April 2017
Why Docker? Dayton PHP, April 2017
 
From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017
 
Docker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPDocker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHP
 
How We Got Here: A Brief History of Open Source
How We Got Here: A Brief History of Open SourceHow We Got Here: A Brief History of Open Source
How We Got Here: A Brief History of Open Source
 
Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016
 
From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016
 

Recently uploaded

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 

Recently uploaded (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 

OOP is More Than Just Animals

  • 1. OOP is More Than Cats and Dogs Chris  Tankersley   LonestarPHP  2015   LonestarPHP  2015   1  
  • 2. Who Am I •  PHP  Programmer  for  over  10  years   •  Work/know  a  lot  of  different   languages,  even  COBOL   •  Primarily  do  Zend  Framework  2   •  hFps://github.com/dragonmantank   LonestarPHP  2015   2  
  • 3. Quick Vocabulary Lesson •  Class  –  DefiniOon  of  code   •  Object  –  InstanOaOon  of  a  Class   •  Member  –  Variable  belonging  to  a  class   •  Method  –  FuncOon  belonging  to  a  class   There  will  be  more  as  we  go  along   LonestarPHP  2015   3  
  • 4. LonestarPHP  2015   4   Class class Employee { protected $name; // This is a member protected $number; // This is a Method public function setData($data) { $this->name = $data['name']; $this->number = $data['number']; } public function viewData() { echo <<<ENDTEXT Name: {$this->name} Number: {$this->number} ENDTEXT; } }
  • 5. Object •  <?php! •  $manager= new Manager();! •  // ^! •  // |! •  // `--- This is the Object   LonestarPHP  2015   5  
  • 6. Why are we using OOP? LonestarPHP  2015   6  
  • 7. Let’s count the reasons •  Because  we’re  told  to,  procedural  programming  leads  to  spagheX   code   •  We  deal  with  objects  every  day,  so  it  shouldn’t  be  too  hard   •  We  want  to  allow  for  code  re-­‐use   •  We  want  to  group  like  code  together   •  We  want  to  easily  extend  our  code   •  We  want  to  be  able  to  easily  test  our  code   LonestarPHP  2015   7  
  • 8. Getting OOP Right can be Complicated •  Animals  can  speak,  and  have  legs  and  fur.  Let’s  make  objects  based   on  that   •  Dogs  are  animals,  and  so  are  cats   •  What  about  Fish?   •  Cars  have  doors,  engines,  and  colors.  They  only  go  so  fast.  Let’s   model  that   •  Motorcycles  aren’t  Cars,  so  let’s  refactor  Cars   •  Holy  crap  there  are  a  lot  of  engines…  and  wheels…     LonestarPHP  2015   8  
  • 9. Can a Dog have Wheels? •  Discuss  (or  listen  to  me  talk  some  more)   LonestarPHP  2015   9  
  • 11. What we’re all taught •  Classes  are  “things”  in  the  real  world   •  We  should  construct  class  members  based  on  AFributes   •  Number  of  wheels   •  Sound  it  makes   •  We  should  construct  class  methods  based  on  “AcOons”   •  Running   •  Speaking   •  Jumping   LonestarPHP  2015   11  
  • 12. New Vocabulary •  Parent  Class  –  Class  that  is  extended   •  Child  Class  –  Class  that  is  extending  another  class   In  PHP,  a  class  can  be  both  a  Child  and  a  Parent  at  the  same  Ome   LonestarPHP  2015   12  
  • 13. Where I Learned It LonestarPHP  2015   13  
  • 14. Our Structure LonestarPHP  2015   14   Employee   Manager   ScienOst   Laborer  
  • 15. The Employee Class LonestarPHP  2015   15   abstract class Employee { protected $name; // Employee Name protected $number; // Employee Number public function setData($data) { $this->name = $data['name']; $this->number = $data['number']; } public function viewData() { echo <<<ENDTEXT Name: {$this->name} Number: {$this->number} ENDTEXT; } }
  • 16. The Manager Class LonestarPHP  2015   16   class Manager extends Employee { protected $title; // Employee Title protected $dues; // Golf Dues public function setData($data) { parent::setData($data); $this->title = $data['title']; $this->dues = $data['dues']; } public function viewData() { parent::viewData(); echo <<<ENDTEXT Title: {$this->title} Golf Dues: {$this->dues} ENDTEXT; } }
  • 17. The Scientist Class LonestarPHP  2015   17   class Scientist extends Employee { protected $pubs; // Number of Publications public function setData($data) { parent::setData($data); $this->pubs = $data['pubs']; } public function viewData() { parent::viewData(); echo <<<ENDTEXT Publications: {$this->pubs} ENDTEXT; } }
  • 18. The Laborer Class LonestarPHP  2015   18   class Laborer extends Employee { }
  • 19. What does this teach us? •  Inheritance   •  Makes  it  easier  to  group  code  together  and  share  it  amongst  classes   •  Allows  us  to  extend  code  as  needed   •  PHP  allows  Single  inheritance   LonestarPHP  2015   19  
  • 20. We use it all the time namespace ApplicationController;! ! use ZendMvcControllerAbstractActionController;! use ZendViewModelViewModel;! ! Class IndexController extends AbstractActionController! {! public function indexAction()! {! /** @var VendorVendorService $vendor */! $vendor = $this->serviceLocator->get('VendorVendorService');! ! $view = new ViewModel();! return $view;! }! }   LonestarPHP  2015   20  
  • 21. Why it Works (Most of the time, Kinda) •  Allows  us  to  extend  things  we  didn’t  necessarily  create   •  Encourages  code  re-­‐use   •  Allows  developers  to  abstract  away  things   LonestarPHP  2015   21  
  • 22. How to use it •  Understand  the  difference  between  Public,  Protected,  and  Private   •  Public  –  Anyone  can  use  this,  even  children   •  Protected  –  Anything  internal  can  use  this,  even  children   •  Private  –  This  is  mine,  hands  off   •  Abstract  vs  Concrete  Classes   •  Abstract  classes  cannot  be  instanOated  directly,  they  must  be  extended   LonestarPHP  2015   22  
  • 23. The Employee Class LonestarPHP  2015   23   abstract class Employee { protected $name; // Employee Name protected $number; // Employee Number public function setData($data) { $this->name = $data['name']; $this->number = $data['number']; } public function viewData() { echo <<<ENDTEXT Name: {$this->name} Number: {$this->number} ENDTEXT; } }
  • 24. The Manager Class LonestarPHP  2015   24   class Manager extends Employee { protected $title; // Employee Title protected $dues; // Golf Dues public function setData($data) { parent::setData($data); $this->title = $data['title']; $this->dues = $data['dues']; } public function viewData() { parent::viewData(); echo <<<ENDTEXT Title: {$this->title} Golf Dues: {$this->dues} ENDTEXT; } }
  • 25. An Example <?php! // Cannot do this. This will throw the following error:! // Fatal error: Cannot instantiate abstract class Employee! $employee = new Employee(); ! // We can do this though!! $manager = new Manager(); ! // Name is protected, so we can't do this. This throws:! // Fatal error: Cannot access protected property Manager::$name! $manager->name = 'Bob McManager’;! // setData is public, so we can use that! $manager->setData(['name' => 'Bob McManager’,'number' => 1]);! // We can also view the data, since it's public! $manager->viewData();   LonestarPHP  2015   25  
  • 26. Why can Inheritance Be Bad •  PHP  only  allows  Single  Inheritance  on  an  Class   •  You  can  have  a  series  of  Inheritance  though,  for  example  CEO  extends   Manager,  Manager  extends  Employee   •  Long  inheritance  chains  can  be  a  code  smell   •  Private  members  and  methods  cannot  be  used  by  Child  classes   •  Single  Inheritance  can  make  it  hard  to  ‘bolt  on’  new  funcOonality   between  disparate  classes   LonestarPHP  2015   26  
  • 28. The General Idea •  Classes  contain  other  classes  to  do  work  and  extend  that  way,  instead   of  through  Inheritance   •  Interfaces  define  “contracts”  that  objects  will  adhere  to   •  Your  classes  implement  interfaces  to  add  needed  funcOonality   LonestarPHP  2015   28  
  • 29. Interfaces interface EmployeeInterface {! protected $name;! protected $number;! ! public function getName();! public function setName($name);! public function getNumber();! public function setNumber($number);! }! ! interface ManagerInterface {! protected $golfHandicap;! ! public function getHandicap();! public function setHandicap($handicap);! }   LonestarPHP  2015   29  
  • 30. Interface Implementation class Employee implements EmployeeInterface {! public function getName() {! return $this->name;! }! public function setName($name) {! $this->name = $name;! }! }! class Manager implements EmployeeInterface, ManagerInterface {! // defines the employee getters/setters as well! public function getHandicap() {! return $this->handicap; ! }! public function setHandicap($handicap) {! $this->handicap = $handicap;! }! }   LonestarPHP  2015   30  
  • 31. This is Good and Bad •  “HAS-­‐A”  is  tends  to  be  more  flexible  than  “IS-­‐A”   •  Somewhat  easier  to  understand,  since  there  isn’t  a  hierarchy  you   have  to  backtrack     •  Each  class  must  provide  their  own  ImplementaOon,  so  can  lead  to   code  duplicaOon   LonestarPHP  2015   31  
  • 32. Traits •  Allows  small  blocks  of  code  to  be  defined  that  can  be  used  by  many   classes   •  Useful  when  abstract  classes/inheritance  would  be  cumbersome   •  My  Posts  and  Pages  classes  should  need  to  extend  a  Slugger  class  just  to   generate  slugs.     LonestarPHP  2015   32  
  • 33. Avoid Code-Duplication with Traits trait EmployeeTrait {! public function getName() {! return $this->name;! }! public function setName($name) {! $this->name = $name;! }! }! class Employee implements EmployeeInterface {! use EmployeeTrait;! }! class Manager implements EmployeeInterface, ManagerInterface {! use EmployeeTrait;! use ManagerTrait;! }   LonestarPHP  2015   33  
  • 34. Taking Advantage of OOP LonestarPHP  2015   34  
  • 36. What is Coupling? •  Coupling  is  how  dependent  your  code  is  on  another  class   •  The  more  classes  you  are  coupled  to,  the  more  changes  affect  your   class   LonestarPHP  2015   36  
  • 37. <?php! ! namespace ApplicationController;! ! use ZendMvcControllerAbstractActionController;! use ZendViewModelViewModel;! ! class MapController extends AbstractActionController! {! public function indexAction()! {! // Position is an array with a Latitude and Longitude object! $position = $this->getServiceLocator()->get('MapService’)! ->getLatLong('123 Main Street', 'Defiance', 'OH');! echo $position->latitude->getPoint();! }! }   LonestarPHP  2015   37  
  • 38. Law of Demeter LonestarPHP  2015   38  
  • 40. What is Dependency Injection? •  InjecOng  dependencies  into  classes,  instead  of  having  the  class  create   it   •  Allows  for  much  easier  tesOng   •  Allows  for  a  much  easier  Ome  swapping  out  code   •  Reduces  the  coupling  that  happens  between  classes   LonestarPHP  2015   40  
  • 41. Method Injection class MapService {! public function getLatLong(GoogleMaps $map, $street, $city, $state) {! return $map->getLatLong($street . ' ' . $city . ' ' . $state);! }! ! public function getAddress(GoogleMaps $map, $lat, $long) {! return $map->getAddress($lat, $long);! }! }   LonestarPHP  2015   41  
  • 42. Constructor Injection class MapService {! protected $map;! public function __construct(GoogleMaps $map) {! $this->map = $map;! }! public function getLatLong($street, $city, $state) {! return $this! ->map! ->getLatLong($street . ' ' . $city . ' ' . $state);! }! }! !   LonestarPHP  2015   42  
  • 43. Setter Injection class MapService {! protected $map;! ! public function setMap(GoogleMaps $map) {! $this->map = $map;! }! public function getMap() {! return $this->map;! }! public function getLatLong($street, $city, $state) {! return $this->getMap()->getLatLong($street . ' ' . $city . ' ' . $state);! }! }!   LonestarPHP  2015   43  
  • 45. Single Responsibility Principle •  Every  class  should  have  a  single  responsibility,  and  that  responsibility   should  be  encapsulated  in  that  class   LonestarPHP  2015   45  
  • 46. What is a Responsibility? •  Responsibility  is  a  “Reason  To  Change”  –  Robert  C.  MarOn   •  By  having  more  than  one  “Reason  to  Change”,  code  is  harder  to   maintain  and  becomes  coupled   •  Since  the  class  is  coupled  to  mulOple  responsibiliOes,  it  becomes   harder  for  the  class  to  adapt  to  any  one  responsibility     LonestarPHP  2015   46  
  • 47. An Example /** * Create a new invoice instance. * * @param LaravelCashierContractsBillable $billable * @param object * @return void */ public function __construct(BillableContract $billable, $invoice) { $this->billable = $billable; $this->files = new Filesystem; $this->stripeInvoice = $invoice; } /** * Create an invoice download response. * * @param array $data * @param string $storagePath * @return SymfonyComponentHttpFoundationResponse */ public function download(array $data, $storagePath = null) { $filename = $this->getDownloadFilename($data['product']); $document = $this->writeInvoice($data, $storagePath); $response = new Response($this->files->get($document), 200, [ 'Content-Description' => 'File Transfer', 'Content-Disposition' => 'attachment; filename="'.$filename.'"', 'Content-Transfer-Encoding' => 'binary', 'Content-Type' => 'application/pdf', ]); $this->files->delete($document); return $response; } LonestarPHP  2015   47   hFps://github.com/laravel/cashier/blob/master/src/Laravel/Cashier/Invoice.php  
  • 48. Why is this Bad? •  This  single  class  has  the  following  responsibiliOes:   •  GeneraOng  totals  for  the  invoice  (including  discounts/coupons)   •  GeneraOng  an  HTML  View  of  the  invoice  (Invoice::view())   •  GeneraOng  a  PDF  download  of  the  invoice(Invoice::download())   •  This  is  coupled  to  a  shell  script  as  well   •  Two  different  displays  handled  by  the  class.  Adding  more  means   more  responsibility   •  Coupled  to  a  specific  HTML  template,  the  filesystem,  the  Laravel   Views  system,  and  PhantomJS  via  the  shell  script   LonestarPHP  2015   48  
  • 49. How to Improve •  Change  responsibility  to  just  building  the  invoice  data   •  Move  the  ‘output’  stuff  to  other  classes   LonestarPHP  2015   49  
  • 51. This is not a testing talk •  Using  Interfaces  makes  it  easier  to  mock  objects   •  Reducing  coupling  and  following  Demeter’s  Law  makes  you  have  to   mock  less  objects   •  Dependency  InjecOon  means  you  only  mock  what  you  need  for  that   test   •  Single  Responsibility  means  your  test  should  be  short  and  sweet   •  Easier  tesOng  leads  to  more  tesOng   LonestarPHP  2015   51  
  • 53. We can make a dog with wheels! •  Abstract  class  for  Animal   •  Class  for  Dog  that  extends  Animal   •  Trait  for  Wheels   •  With  the  write  methodology,  we  could  even  unit  test  this   In  the  real  world,  we  can  now  represent  a  crippled  dog   LonestarPHP  2015   53  
  • 54. Here’s a cute dog instead LonestarPHP  2015   54  
  • 55. Thank You! hFp://ctankersley.com   chris@ctankersley.com   @dragonmantank     hFps://joind.in/13542   LonestarPHP  2015   55