SlideShare a Scribd company logo
1 of 104
Download to read offline
WE FACE SIMILAR
PROBLEMS.
—OFTEN—
THOSE PROBLEMS HAVE
COMMON SOLUTIONS.
“DESIGN PATTERNS”
=
COMMON SOLUTIONS
TO COMMON PROBLEMS
DESIGN PATTERN BENEFITS
• Presents a common solution to a problem.
• Common solution = faster implementation
• Recognizable to other developers.
• Encourages more legible and maintainable code.
TERMINOLOGY
• Interface:
• An outline or a blueprint for classes. Cannot be instantiated.
• Abstract class:
• A class that can serve as an outline, while providing base
functionality of its own. Can implement an interface. Cannot be
instantiated.
TERMINOLOGY
• Concrete class:
• A “creatable” class. Can implement an interface or extend an
abstract or concrete class. Can be instantiated.
DEPENDENCY INJECTION
FACTORY
STRATEGY
CHAIN OF RESPONSIBILITY (COR)
class Session()
{
function __construct() {
session_start();
}
function getCreatedTime()
{
return $_SESSION[…];
}
}
public function getSession()
{
return new Session();
}
$app = new App();
echo $app->getSession()->getCreatedTime();
sleep(2);
echo $app->getSession()->getCreatedTime();
SINGLETONS
The way it used to be done: a global means to access
one instance of an object
SOLUTION?
• Use static class methods to track single instance
of object:
public static function getInstance()
{
if (!self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
SOLUTION?
• Then, get the class like so:
public function getSession()
{
return Session::getInstance();
}
Model needs session
class Session
Create instance and
store it.
self::
$_instance?
Return instance.
No
Yes
SINGLETON’S PROBLEMS:
• Hard links the session to its consuming class.
• Makes testing more difficult.
• Breaks Single Responsibility Principle, as the class
manages its own instance.
DEPENDENCY INJECTION (DI)
Providing classes the variables they need.
S
Title Text
DI DESIGN
new Model($session);
$session = new Session();
DI DESIGN
new Model($session);
$session = new Session();
new Controller($session);
DI DESIGN
new Model($session);
$session = new Session();
new Controller($session);
new DataStorage($session);
DI
• We create the objects and then “inject” them into
each class that depends on them.
• Benefits:
• Easier to follow Single Responsibility Principle.
• Makes testing easier: we can inject mocks or
stubs.
• Good visibility into what each class needs.
protected $session;
public function __construct(Session $session)
{
$this->session = $session;
}
public function saveToSession($value)
{
$this->session->save(‘time’, $value);
}
public function getFromSession()
{
return $this->session->get(‘time’);
}
$session = new Session();
$app = new App($session);
$app->saveToSession(time());
echo $app->getFromSession();
DI CONTAINERS
Grouping variables into an object to be inserted into a class.
new App(); new Session(); DI Container
class App {
protected $session;
function __construct(Container $container) {
$this->session = $container->get(‘session’);
}
}
DI CONTAINERS
• Pimple (pimple.sensiolabs.org)
• Super simple container but is rather manual.
• PHP-DI (http://php-di.org/)
• More complex to setup but injection is
automatic.
• Similar to Symphony Dependency Injection component: 

https://github.com/symfony/DependencyInjection
USE CASES:
• Database connections
• Sessions
• Other objects in a request’s lifecycle.
DEPENDENCY INJECTION
FACTORY
STRATEGY
CHAIN OF RESPONSIBILITY (COR)
FACTORY
Allows centralization of code for class construction.
$controller = new HomeController(
$request,
$response,
$templateEngine,
$cookieJar,
$properties,
// …
);
Too many properties
to call frequently.
FACTORY
• We manufacture very little of what we own.
• Factories make most of our possessions for us.
• Single-purposed: making things.
FACTORY DEFINED:
• Moves the task of creating classes to a
single-purposed class, the factory.
• Factory provides a simple method to
instantiate new class.
$application
Constructor
Arguments
new Controller(…)
$application
ControllerFactory::load()
Constructor
Arguments
new Controller(…)
“I need a Controller class.”
$application
ControllerFactory::load()
Constructor
Arguments
new Controller(…)
FACTORY:
• Create a class as the factory.
• All classes instantiated should extend a
common type or implement a common
interface.
• Return the newly created class.
FACTORY:
• Extra kudos: you can use a configuration file
(Yaml/Xml) to control the creation of the
classes.
public function loadProduct($id)
{
$data = $this->getProductDataFor($id);
return ProductFactory::hydrate($data);
}
class ProductFactory
{
public static function hydrate($data)
{
switch ($data[‘type’]) {
case ‘simple’:
$product = new SimpleProduct($data);
break;
case ‘configurable’:
$product = new ConfigProduct($data);
break;
}
return $product;
}
}
products:
simple:
name: Simple Product
class: ModelProductSimple
child_selector:
name: Configurable
class: ModelProductConfigurable
class ProductFactory
{
public static function hydrate($data, $config)
{
$type = $data[‘type’];
$className = $config[‘products’][$type][‘class’];
$product = new $className($data);
return $product;
}
}
USE CASES:
• Factory is a design-pattern for instantiating classes.
• Offloading the creation of parameter-heavy
constructors:
• Dependency Injection
• Determine what type of class to setup.
• Gives means for 3rd-party developers to extend
the functionality of your software.
DEPENDENCY INJECTION
FACTORY
STRATEGY
CHAIN OF RESPONSIBILITY (COR)
STRATEGY
Pluggable objects that have the same interface but
can do different things.
PROBLEM:
• How to separate changeable details?
public function persist($data, $to)
{
switch($to) {
case 'mysql':
$connection = new PDO(...);
$connection->exec(...);
break;
case 'salesforce':
$connection = new HttpClient(...);
// ...
break;
}
}
PROBLEM:
public function persist($data, $to)
{
switch($to) {
case 'mysql':
// …
case 'salesforce':
// …
case 'redis':
// …
}
}
PROBLEM:
public function persist($data, $to)
{
switch($location) {
case 'mysql':
// …
case 'salesforce':
// …
case 'redis':
// …
case 'file':
// …
}
}
PROBLEM:
public function persist($data, $to)
{
switch($location) {
case 'mysql':
// …
case 'salesforce':
// …
case 'redis':
// …
case 'file':
// …
case 'ec2':
// …
}
}
PROBLEM:
public function persist($data, $to)
{
switch($location) {
case 'mysql':
// …
case 'salesforce':
// …
case 'redis':
// …
case 'file':
// …
case 'ec2':
// …
case 'dropbox':
// …
}
}
THIS CAN QUICKLY BECOME
UNMANAGEABLE….
UPDATED:
public function persist($data, $to)
{
switch($location) {
case 'mysql':
$this->persistToMysql($data);
case 'salesforce':
$this->persistToSalesForce($data);
case 'redis':
$this->persistToRedis($data);
case 'file':
$this->persistToFile($data);
case 'ec2':
$this->persistToEc2($data);
case 'dropbox':
$this->persistToDrop($data);
}
}
…BUT THERE’S A BETTER WAY.
FORD
MUSTANG
Engines:
5.2L V8
5.0L V8
2.3L EcoBoost
DRILL
http://www.dewalt.com/tool-categories/Drills.aspx
STRATEGY
• Parent class handles “what” happens.
• Child class handles “how” it happens.
• Parent doesn’t know who the child is.
• The children must all expose the same methods.
• Factory:
• initializes objects, returns them for use
• should expose a similar set of methods
• Strategy:
• uses objects
• must expose a similar set of methods
Data Storage (parent: “what happens”)
Provider (child: “how it happens”)
save()load() update()
save()load() update()
list()
Data Storage
MySqlProvider
save()load() update()
save()load() update()
connect()
Data Storage
SalesForceProvider
save()load() update()
save()load() update()
push()
Data Storage
MySqlProvider SalesForceProviderOR:
class DataStorage //parent: “what happens”
{
protected $provider; //child: “how it happens”
public function __construct ($provider)
{
$this->provider = $provider;
}
public function update ($model)
{
$this->provider->update($model);
}
}
interface ProviderInterface
{
/**
* This is the blueprint for the provider,
* the child.
*/
public function update($model);
}
class MySqlProvider implements ProviderInterface
{
/**
* Child MySqlProvider
*/
public function update($model)
{
$connection = $this->getConnection();
$connection->exec('UPDATE … SET');
return $this;
}
}
class SalesForceProvider
{
/**
* Child SalesForceProvider
*/
public function update($model)
{
$client = new GuzzleHttpClient();
$client->request('POST', ‘{url}’);
// ...
}
}
class DataStorage { /* … */ }
interface ProviderInterface { /* … */ }
class MysqlProvider { /* … */ }
class SalesForceProvider { /* … */ }
// using our strategy design pattern:
$storage = new DataStorage(new MysqlProvider);
$storage->update($data);
STRATEGY USES:
• Any case where different algorithms or methods
are needed to be interchangeable, but only one
used:
• Storage locations
• Computational Algorithms
DEPENDENCY INJECTION
FACTORY
STRATEGY
CHAIN OF RESPONSIBILITY (COR)
CHAIN OF RESPONSIBILITY
Handling logic through multiple links/siblings of functionality.
PROBLEM:
• Cascading layers of caching.
• How to get the value from the list?
• Cascading renderers for a component.
• How to have renderers determine who should
render?
public function get($key)
{
$redis = new Redis();
$db = new Db();
$file = new File();
if ($redisVal = $redis->get($key)) {
return $redisVal;
} else if ($dbVal = $db->get($key)) {
return $dbVal;
} else if ($fileVal = $$file->get($key)) {
return $fileVal;
}
return '';
}
SOLUTION #1: LOOPS
• Easier, but less flexible.
• Iterate through each member of an array of the
items and have that member check to determine
its legibility.
public function get($key)
{
$cacheTypes = ['Redis', 'Db', 'File'];
$value = '';
foreach ($cacheTypes as $cacheType) {
$className = new "ModelCache{$cacheType}";
$cache = new $className();
if ($value = $cache->get($key)) {
break;
}
}
return $value;
}
SOLUTION #2: COR
• Horizontal chaining: sibling relationships
• Parent class interacts with first item in the chain.
FileDBRedis
Entry Point
File: no next link :(
DB: $this->_nextLink
Redis: $this->_nextLink
SOLUTION #2: COR
• Each link inherits from a abstract class.
• Abstract class handles chaining.
• Concrete objects provide functionality for
processing and whether or not to proceed.
COR DESIGN
Need something
from the cache
FileSystemDBRedis
processed? processed? processed?
No
Yes!
AbstractCache
SETUP STEPS:
• Instantiate first link.
• Create next link.
• Append to first link.
• Continue…
USAGE STEPS:
• Call first link’s get method.
• Will check itself.
• If no value, and next link, call that link.
• Repeat…
<?php
class Request
{
protected $_key;
protected $_result;
public function setKey($value) { /**/ }
public function getResult() { /**/ }
}
<?php
abstract class Base
{
protected $_nextLink;
protected $_result;
protected $_data;
abstract protected function getDataFor($key);
public function append(Base $nextLink) { /**/ }
public function get($request) { /**/ }
public function processing($request) { /**/ }
}
<?php
abstract class Base
{
protected $_nextLink;
protected $_result;
protected $_data;
abstract protected function getDataFor($key);
public function append(Base $nextLink) { /**/ }
public function get($request) { /**/ }
public function processing($request) { /**/ }
}
<?php
abstract class Base
{
protected $_nextLink;
protected $_result;
protected $_data;
abstract protected function getDataFor($key);
public function append(Base $nextLink) { /**/ }
public function get($request) { /**/ }
public function processing($request) { /**/ }
}
<?php
abstract class Base
{
protected $_nextLink;
protected $_result;
protected $_data;
abstract protected function getDataFor($key);
public function append(Base $nextLink) { /**/ }
public function get($request) { /**/ }
public function processing($request) { /**/ }
}
<?php
abstract class Base
{
protected $_nextLink;
protected $_result;
protected $_data;
abstract protected function getDataFor($key);
public function append(Base $nextLink) { /**/ }
public function get($request) { /**/ }
public function processing($request) { /**/ }
}
<?php
abstract class Base
{
protected $_nextLink;
protected $_result;
protected $_data;
abstract protected function getDataFor($key);
public function append(Base $nextLink) {
if (!$this->_nextLink) {
$this->_nextLink = $nextLink;
} else {
$this->_nextLink->append($nextLink);
}
}
public function get($request) { /**/ }
public function processing($request) { /**/ }
public function getSuccessor() { /**/ }
}
abstract protected function getDataFor($key);
public function append(Base $nextLink) { /* … */}
public function get($request) {
if (!($request instanceof Request)) {
$key = $request;
$request = new Request();
$request->setKey($key);
}
$success = $this->processing($request);
if (!$success && $this->_nextLink) {
$this->_nextLink->get($request);
}
return $request->getResult();
}
public function processing($request) { /* … */ }
abstract protected function getDataFor($key);
public function append(Base $nextLink) { /* … */}
public function get($request) {
if (!($request instanceof Request)) {
$key = $request;
$request = new Request();
$request->setKey($key);
}
$success = $this->processing($request);
if (!$success && $this->_nextLink) {
$this->_nextLink->get($request);
}
return $request->getResult();
}
public function processing($request) { /* … */ }
public function get($request) { /* … */ }
public function processing($request) {
$key = $request->getKey();
$value = $this->getDataFor($key);
if ($value) {
$request->setResult($value);
return true;
} else {
return false;
}
}
public function getNextLink() { /* ... */}
}
class RedisCache extends Base
{
protected function getDataFor($key)
{
// connects to redis and returns value
}
}
$redis = new RedisCache();
$redis->append(new DbCache)
->append(new FileCache);
return $redis->get('key_name');
USAGE STEPS:
• Call first link’s get method.
• Will check itself.
• If no value, and next link, call that link.
• Repeat…
USE CASES:
• Layers of caching
• Rendering views with a standard input, but giving
each member the equal opportunity to display.
• Iterating through strategies to find a solution to an
algorithm.
DEPENDENCY INJECTION
FACTORY
STRATEGY
CHAIN OF RESPONSIBILITY (COR)
REVIEW
DI Factory Strategy CoR
Class has
everything it needs
on construction.
Creation: Chooses
and creates any
object from options.
Action: Similar
interface for
different
applications.
Interacts with
options to retrieve
output.
All use specific classes to maintain Single Responsibility Principle.
RESOURCES
• Design Patterns: Elements of Reusable Object-
Oriented Software
• (Gamma, Helm, Johnson, Vlissides; published by Addison-Wesley)
• Design Patterns PHP
• http://designpatternsphp.readthedocs.org/en/latest/
• PHP the Right Way
• http://www.phptherightway.com/
FEEDBACK?https://joind.in/14702

More Related Content

What's hot

EPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur PurnamaEPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
Enterprise PHP Center
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
Yi-Huan Chan
 
Test in action week 3
Test in action   week 3Test in action   week 3
Test in action week 3
Yi-Huan Chan
 
Test in action week 4
Test in action   week 4Test in action   week 4
Test in action week 4
Yi-Huan Chan
 

What's hot (19)

Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
PHP MVC
PHP MVCPHP MVC
PHP MVC
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStorm
 
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur PurnamaEPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
 
Test in action week 3
Test in action   week 3Test in action   week 3
Test in action week 3
 
Continuous Quality Assurance
Continuous Quality AssuranceContinuous Quality Assurance
Continuous Quality Assurance
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
PHPSpec BDD Framework
PHPSpec BDD FrameworkPHPSpec BDD Framework
PHPSpec BDD Framework
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Test in action week 4
Test in action   week 4Test in action   week 4
Test in action week 4
 

Viewers also liked

Viewers also liked (17)

Driving Design with PhpSpec
Driving Design with PhpSpecDriving Design with PhpSpec
Driving Design with PhpSpec
 
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-ControllerAction-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 
Giving birth to an ElePHPant
Giving birth to an ElePHPantGiving birth to an ElePHPant
Giving birth to an ElePHPant
 
JWT - To authentication and beyond!
JWT - To authentication and beyond!JWT - To authentication and beyond!
JWT - To authentication and beyond!
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
 
Programming with Cmdr. Chris Hadfield
Programming with Cmdr. Chris HadfieldProgramming with Cmdr. Chris Hadfield
Programming with Cmdr. Chris Hadfield
 
Enterprise Architecture Case in PHP (MUZIK Online)
Enterprise Architecture Case in PHP (MUZIK Online)Enterprise Architecture Case in PHP (MUZIK Online)
Enterprise Architecture Case in PHP (MUZIK Online)
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful Security
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)
 
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
 
What's New In PHP7
What's New In PHP7What's New In PHP7
What's New In PHP7
 
Hexagonal architecture message-oriented software design
Hexagonal architecture   message-oriented software designHexagonal architecture   message-oriented software design
Hexagonal architecture message-oriented software design
 
install PHP7 on CentOS7 by Ansible
install PHP7 on CentOS7 by Ansibleinstall PHP7 on CentOS7 by Ansible
install PHP7 on CentOS7 by Ansible
 

Similar to PHP: 4 Design Patterns to Make Better Code

Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
Alexei Gorobets
 
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Fabien Potencier
 

Similar to PHP: 4 Design Patterns to Make Better Code (20)

Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
 
10 PHP Design Patterns #burningkeyboards
10 PHP Design Patterns #burningkeyboards10 PHP Design Patterns #burningkeyboards
10 PHP Design Patterns #burningkeyboards
 
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
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
 
OOP Is More Than Cars and Dogs
OOP Is More Than Cars and DogsOOP Is More Than Cars and Dogs
OOP Is More Than Cars and Dogs
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
 
Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2
 
Multilingualism makes better programmers
Multilingualism makes better programmersMultilingualism makes better programmers
Multilingualism makes better programmers
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
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
 
From framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytvFrom framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytv
 
Migrating to dependency injection
Migrating to dependency injectionMigrating to dependency injection
Migrating to dependency injection
 
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)
 
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
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
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Objects, Testing, and Responsibility
Objects, Testing, and ResponsibilityObjects, Testing, and Responsibility
Objects, Testing, and Responsibility
 

More from SWIFTotter Solutions

More from SWIFTotter Solutions (6)

Developing a Web-Based business
Developing a Web-Based businessDeveloping a Web-Based business
Developing a Web-Based business
 
Magento SEO Tips and Tricks
Magento SEO Tips and TricksMagento SEO Tips and Tricks
Magento SEO Tips and Tricks
 
Composer and Git in Magento
Composer and Git in MagentoComposer and Git in Magento
Composer and Git in Magento
 
eCommerce Primer - Part 1
eCommerce Primer - Part 1eCommerce Primer - Part 1
eCommerce Primer - Part 1
 
A brief introduction to CloudFormation
A brief introduction to CloudFormationA brief introduction to CloudFormation
A brief introduction to CloudFormation
 
Demystifying OAuth2 for PHP
Demystifying OAuth2 for PHPDemystifying OAuth2 for PHP
Demystifying OAuth2 for PHP
 

Recently uploaded

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
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
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 

PHP: 4 Design Patterns to Make Better Code

Editor's Notes

  1. Great to be with everyone. I have appreciated this, as these events have tremendously improved my coding.
  2. Going to cover three tonight. Hopefully you can implement at least one into your coding practices. Remember when John Kary recommended to have a maximum of 10 lines of code in a function: tremendously cleaned up my code.
  3. Had to put a meme in here, with a tacky transition.
  4. For DI, you can inject anything: variables such as credentials, configuration settings, class names, etc.
  5. Append puts together the chain, get iterates through the chain, processing determines whether the class can handle request, getDataFor($key) retrieves the data and returns it to processing.