SlideShare uma empresa Scribd logo
1 de 34
Baixar para ler offline
Common PHP Design
Patterns
David Stockton
Front Range PHP User Group - Feb 18, 2015
What are design patterns?
Common Language
Gang of Four
Cartman, Kyle, Stan, Kenny
Gang of Four
Gamma, Helm, Johnson, Vlissides
What aren’t design patterns?
Silver Bullets
Legos for Coding
Scratch is Legos
for Coding
This talk is not about scratch
Design Patterns
Help You Talk to
Other Coders
Hey, I’m building a chunk
of code that is used to
build an object which has
a lot of dependencies and
setup and each of those
has a few of their own so
this piece of code will take
care of putting together all
those pieces so that when
I need the object I just
have to ask this one object
to give me the other one
and then I can use it where
ever I need instead of
having to build a huge
dependency tree before
using this code…
LOL
WUT?
I’m building a factory.
What does a factory do?
• Builds objects
• Encapsulates building of objects so there’s only one
place to find how to build it
Singleton
Singleton
There can be only one
Singleton
• For classes where we want only one instance
Downsides of Singleton
• It is a global
• Hard to test
• Better ways to do this
Another pattern description
• I’m going to create a shopping cart where I can
choose how the discounts or promo codes will be
applied by injecting various objects, each of which can
include how to apply these discounts; for example
apply discounts only to items that don’t have other
discounts, apply discount percentage on the base
price not counting already applied discounts, apply
discount percentage after other applied discounts,
apply a flat amount of a discount for each item, apply
a discount on an item based on what type of item it is,
etc
Strategy pattern
• I’m going to create a shopping cart where I can
choose how the discounts or promo codes will be
applied by injecting various objects, each of which can
include how to apply these discounts; for example
apply discounts only to items that don’t have other
discounts, apply discount percentage on the base
price not counting already applied discounts, apply
discount percentage after other applied discounts,
apply a flat amount of a discount for each item, apply
a discount on an item based on what type of item it is,
etc
Strategy pattern
• Allow injection of object that provides some aspect of
the functionality
• Algorithm’s functionality can be decided at run-time
• Examples:
• usort - Provide comparison part of sort
• Car - brakingStrategy
Command Pattern
• I’m doing a bunch of stuff that I want to be able to
keep track of and potentially save and replay later,
possibly be able to undo. In order for this to work my
object will have to capture everything it needs to know
about as far as parameters and what-not in order to be
able to run later as well as potentially capturing state
so I can get back to where I was before.
Command Pattern
• Uses:
• Recording Macros
• Multi-level Undo
• Progress Bars
• Transactional Behavior
• Wizards
Chain of Responsibility
• Each object can take care of something (or not), then it
passes to the next object
Chain of Responsibility
Examples
• Loggers - set next logger in chain, each calls the next
when it is done
• Managers with purchasing power - if amount is above
manager’s level, pass to the next object in the chain
Observer Pattern
• Notify interested objects of state changes in subject
• Interested objects subscribe to subject
• When subject changes, it calls update on all observers
MVC - Model View Controller
• Organizational pattern for web dev
• View code contains output
• Model code is for data/business logic
• Controller links model and view code
Front Controller
• Central entry point for handling requests for web
application
• Route all calls through index.php, then figure out what
to do with it
Adapter Pattern
• Allow interface for an existing class to be used from
another interface
Facade Pattern
• Provide simplified access to a complex system
Other Patterns
• Bridge
• Composite
• Decorator
• Front Controller
• Blackboard
• Iterator
• Mediator
• Memento
• Null Object
• Specification
• State
• Template Method
• Visitor
• Abstract Factory
• Prototype
Common design patterns in php

Mais conteúdo relacionado

Mais procurados

How To Become A Good C# Programmer
How To Become A Good C# ProgrammerHow To Become A Good C# Programmer
How To Become A Good C# ProgrammerLearnItFirst.com
 
Clean Code summary
Clean Code summaryClean Code summary
Clean Code summaryJan de Vries
 
Coding standards and guidelines
Coding standards and guidelinesCoding standards and guidelines
Coding standards and guidelinesbrijraj_singh
 
Clean code, Feb 2012
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012cobyst
 
Standard coding practices
Standard coding practicesStandard coding practices
Standard coding practicesAnilkumar Patil
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for javamaheshm1206
 
Best Practices of Software Development
Best Practices of Software DevelopmentBest Practices of Software Development
Best Practices of Software DevelopmentFolio3 Software
 
Reactive GUI Implemented in Clojure
Reactive GUI Implemented in ClojureReactive GUI Implemented in Clojure
Reactive GUI Implemented in Clojuredenyslebediev
 
Geecon10: Object Oriented for nonbelievers
Geecon10: Object Oriented for nonbelieversGeecon10: Object Oriented for nonbelievers
Geecon10: Object Oriented for nonbelieversBruno Bossola
 
Writing code for others
Writing code for othersWriting code for others
Writing code for othersAmol Pujari
 
Design pattern in an expressive language java script
Design pattern in an expressive language java scriptDesign pattern in an expressive language java script
Design pattern in an expressive language java scriptAmit Thakkar
 
Introduction to Frontend Development - Session 1 - HTML Fundamentals
Introduction to Frontend Development - Session 1 - HTML FundamentalsIntroduction to Frontend Development - Session 1 - HTML Fundamentals
Introduction to Frontend Development - Session 1 - HTML FundamentalsKalin Chernev
 
21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir
21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir
21o. RubyFloripa - Maintaining legacy Rails app and introducing ElixirWeverton Timoteo
 

Mais procurados (20)

How To Become A Good C# Programmer
How To Become A Good C# ProgrammerHow To Become A Good C# Programmer
How To Become A Good C# Programmer
 
How to write bad code using C#
How to write bad code using C#How to write bad code using C#
How to write bad code using C#
 
Clean code coding like a professional
Clean code   coding like a professionalClean code   coding like a professional
Clean code coding like a professional
 
Clean Code summary
Clean Code summaryClean Code summary
Clean Code summary
 
Coding standards and guidelines
Coding standards and guidelinesCoding standards and guidelines
Coding standards and guidelines
 
Clean code, Feb 2012
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012
 
Coding standard
Coding standardCoding standard
Coding standard
 
Standard coding practices
Standard coding practicesStandard coding practices
Standard coding practices
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
 
Best Practices of Software Development
Best Practices of Software DevelopmentBest Practices of Software Development
Best Practices of Software Development
 
Reactive GUI Implemented in Clojure
Reactive GUI Implemented in ClojureReactive GUI Implemented in Clojure
Reactive GUI Implemented in Clojure
 
CLEAN CODE
CLEAN CODECLEAN CODE
CLEAN CODE
 
Geecon10: Object Oriented for nonbelievers
Geecon10: Object Oriented for nonbelieversGeecon10: Object Oriented for nonbelievers
Geecon10: Object Oriented for nonbelievers
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 
Writing code for others
Writing code for othersWriting code for others
Writing code for others
 
Clean Code
Clean CodeClean Code
Clean Code
 
Design pattern in an expressive language java script
Design pattern in an expressive language java scriptDesign pattern in an expressive language java script
Design pattern in an expressive language java script
 
Introduction to Frontend Development - Session 1 - HTML Fundamentals
Introduction to Frontend Development - Session 1 - HTML FundamentalsIntroduction to Frontend Development - Session 1 - HTML Fundamentals
Introduction to Frontend Development - Session 1 - HTML Fundamentals
 
Php
PhpPhp
Php
 
21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir
21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir
21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir
 

Destaque

Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3Fabien Potencier
 
Object Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHPObject Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHPRobertGonzalez
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonJonathan Simon
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)paramisoft
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK ExamplesEnder Aydin Orak
 

Destaque (6)

Design patterns in PHP
Design patterns in PHPDesign patterns in PHP
Design patterns in PHP
 
Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3
 
Object Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHPObject Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHP
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK Examples
 

Semelhante a Common design patterns in php

Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patternsRahul Singh
 
Weekly Meeting: Basic Design Pattern
Weekly Meeting: Basic Design PatternWeekly Meeting: Basic Design Pattern
Weekly Meeting: Basic Design PatternNguyen Trung Kien
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven developmentEinar Ingebrigtsen
 
Kaseya Connect 2013: Templates and Policy: The Next Steps
Kaseya Connect 2013: Templates and Policy: The Next StepsKaseya Connect 2013: Templates and Policy: The Next Steps
Kaseya Connect 2013: Templates and Policy: The Next StepsKaseya
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean CodingMetin Ogurlu
 
Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces
Episode 3 – Classes, Inheritance, Abstract Class, and InterfacesEpisode 3 – Classes, Inheritance, Abstract Class, and Interfaces
Episode 3 – Classes, Inheritance, Abstract Class, and InterfacesJitendra Zaa
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certificationKadharBashaJ
 
Unit Testing and role of Test doubles
Unit Testing and role of Test doublesUnit Testing and role of Test doubles
Unit Testing and role of Test doublesRitesh Mehrotra
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...AgileNetwork
 
An Introduction To Software Development - Final Review
An Introduction To Software Development - Final ReviewAn Introduction To Software Development - Final Review
An Introduction To Software Development - Final ReviewBlue Elephant Consulting
 
Create Your Own Starter Files
Create Your Own Starter FilesCreate Your Own Starter Files
Create Your Own Starter FilesEmily Lewis
 
Refactoring Legacy Code - true story
Refactoring Legacy Code - true storyRefactoring Legacy Code - true story
Refactoring Legacy Code - true storyAki Salmi
 
Best practices with development of enterprise-scale SharePoint solutions - Pa...
Best practices with development of enterprise-scale SharePoint solutions - Pa...Best practices with development of enterprise-scale SharePoint solutions - Pa...
Best practices with development of enterprise-scale SharePoint solutions - Pa...SPC Adriatics
 

Semelhante a Common design patterns in php (20)

Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Software Design principales
Software Design principalesSoftware Design principales
Software Design principales
 
Orchestration, the conductor's score
Orchestration, the conductor's scoreOrchestration, the conductor's score
Orchestration, the conductor's score
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patterns
 
Weekly Meeting: Basic Design Pattern
Weekly Meeting: Basic Design PatternWeekly Meeting: Basic Design Pattern
Weekly Meeting: Basic Design Pattern
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
 
Kaseya Connect 2013: Templates and Policy: The Next Steps
Kaseya Connect 2013: Templates and Policy: The Next StepsKaseya Connect 2013: Templates and Policy: The Next Steps
Kaseya Connect 2013: Templates and Policy: The Next Steps
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces
Episode 3 – Classes, Inheritance, Abstract Class, and InterfacesEpisode 3 – Classes, Inheritance, Abstract Class, and Interfaces
Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certification
 
Unit Testing and role of Test doubles
Unit Testing and role of Test doublesUnit Testing and role of Test doubles
Unit Testing and role of Test doubles
 
Clean code
Clean codeClean code
Clean code
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 
An Introduction To Software Development - Final Review
An Introduction To Software Development - Final ReviewAn Introduction To Software Development - Final Review
An Introduction To Software Development - Final Review
 
jForce In Action
jForce In ActionjForce In Action
jForce In Action
 
Create Your Own Starter Files
Create Your Own Starter FilesCreate Your Own Starter Files
Create Your Own Starter Files
 
CPAN Curation
CPAN CurationCPAN Curation
CPAN Curation
 
Refactoring Legacy Code - true story
Refactoring Legacy Code - true storyRefactoring Legacy Code - true story
Refactoring Legacy Code - true story
 
Best practices with development of enterprise-scale SharePoint solutions - Pa...
Best practices with development of enterprise-scale SharePoint solutions - Pa...Best practices with development of enterprise-scale SharePoint solutions - Pa...
Best practices with development of enterprise-scale SharePoint solutions - Pa...
 
Software Design
Software DesignSoftware Design
Software Design
 

Mais de David Stockton

Phone calls and sms from php
Phone calls and sms from phpPhone calls and sms from php
Phone calls and sms from phpDavid Stockton
 
The Art of Transduction
The Art of TransductionThe Art of Transduction
The Art of TransductionDavid Stockton
 
Using queues and offline processing to help speed up your application
Using queues and offline processing to help speed up your applicationUsing queues and offline processing to help speed up your application
Using queues and offline processing to help speed up your applicationDavid Stockton
 
Intermediate OOP in PHP
Intermediate OOP in PHPIntermediate OOP in PHP
Intermediate OOP in PHPDavid Stockton
 
Building APIs with Apigilty and Zend Framework 2
Building APIs with Apigilty and Zend Framework 2Building APIs with Apigilty and Zend Framework 2
Building APIs with Apigilty and Zend Framework 2David Stockton
 
Intermediate OOP in PHP
Intermediate OOP in PHPIntermediate OOP in PHP
Intermediate OOP in PHPDavid Stockton
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profitDavid Stockton
 
Intermediate oop in php
Intermediate oop in phpIntermediate oop in php
Intermediate oop in phpDavid Stockton
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profitDavid Stockton
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profitDavid Stockton
 
Increasing code quality with code reviews (poetry version)
Increasing code quality with code reviews (poetry version)Increasing code quality with code reviews (poetry version)
Increasing code quality with code reviews (poetry version)David Stockton
 
Tame Your Build And Deployment Process With Hudson, PHPUnit, and SSH
Tame Your Build And Deployment Process With Hudson, PHPUnit, and SSHTame Your Build And Deployment Process With Hudson, PHPUnit, and SSH
Tame Your Build And Deployment Process With Hudson, PHPUnit, and SSHDavid Stockton
 
Mercurial Distributed Version Control
Mercurial Distributed Version ControlMercurial Distributed Version Control
Mercurial Distributed Version ControlDavid Stockton
 
Regular expressions and php
Regular expressions and phpRegular expressions and php
Regular expressions and phpDavid Stockton
 

Mais de David Stockton (19)

Phone calls and sms from php
Phone calls and sms from phpPhone calls and sms from php
Phone calls and sms from php
 
The Art of Transduction
The Art of TransductionThe Art of Transduction
The Art of Transduction
 
Using queues and offline processing to help speed up your application
Using queues and offline processing to help speed up your applicationUsing queues and offline processing to help speed up your application
Using queues and offline processing to help speed up your application
 
Intermediate OOP in PHP
Intermediate OOP in PHPIntermediate OOP in PHP
Intermediate OOP in PHP
 
Building APIs with Apigilty and Zend Framework 2
Building APIs with Apigilty and Zend Framework 2Building APIs with Apigilty and Zend Framework 2
Building APIs with Apigilty and Zend Framework 2
 
API All the Things!
API All the Things!API All the Things!
API All the Things!
 
Intermediate OOP in PHP
Intermediate OOP in PHPIntermediate OOP in PHP
Intermediate OOP in PHP
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
Beginning OOP in PHP
Beginning OOP in PHPBeginning OOP in PHP
Beginning OOP in PHP
 
Intermediate oop in php
Intermediate oop in phpIntermediate oop in php
Intermediate oop in php
 
Grokking regex
Grokking regexGrokking regex
Grokking regex
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
Increasing code quality with code reviews (poetry version)
Increasing code quality with code reviews (poetry version)Increasing code quality with code reviews (poetry version)
Increasing code quality with code reviews (poetry version)
 
Tame Your Build And Deployment Process With Hudson, PHPUnit, and SSH
Tame Your Build And Deployment Process With Hudson, PHPUnit, and SSHTame Your Build And Deployment Process With Hudson, PHPUnit, and SSH
Tame Your Build And Deployment Process With Hudson, PHPUnit, and SSH
 
Mercurial Distributed Version Control
Mercurial Distributed Version ControlMercurial Distributed Version Control
Mercurial Distributed Version Control
 
Regular expressions and php
Regular expressions and phpRegular expressions and php
Regular expressions and php
 
PHP 5 Magic Methods
PHP 5 Magic MethodsPHP 5 Magic Methods
PHP 5 Magic Methods
 
FireBug And FirePHP
FireBug And FirePHPFireBug And FirePHP
FireBug And FirePHP
 

Último

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Último (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Common design patterns in php

  • 1. Common PHP Design Patterns David Stockton Front Range PHP User Group - Feb 18, 2015
  • 2. What are design patterns?
  • 4. Gang of Four Cartman, Kyle, Stan, Kenny
  • 5. Gang of Four Gamma, Helm, Johnson, Vlissides
  • 9. Scratch is Legos for Coding This talk is not about scratch
  • 10. Design Patterns Help You Talk to Other Coders
  • 11. Hey, I’m building a chunk of code that is used to build an object which has a lot of dependencies and setup and each of those has a few of their own so this piece of code will take care of putting together all those pieces so that when I need the object I just have to ask this one object to give me the other one and then I can use it where ever I need instead of having to build a huge dependency tree before using this code…
  • 13. I’m building a factory.
  • 14. What does a factory do? • Builds objects • Encapsulates building of objects so there’s only one place to find how to build it
  • 15.
  • 18. Singleton • For classes where we want only one instance
  • 19.
  • 20. Downsides of Singleton • It is a global • Hard to test • Better ways to do this
  • 21. Another pattern description • I’m going to create a shopping cart where I can choose how the discounts or promo codes will be applied by injecting various objects, each of which can include how to apply these discounts; for example apply discounts only to items that don’t have other discounts, apply discount percentage on the base price not counting already applied discounts, apply discount percentage after other applied discounts, apply a flat amount of a discount for each item, apply a discount on an item based on what type of item it is, etc
  • 22. Strategy pattern • I’m going to create a shopping cart where I can choose how the discounts or promo codes will be applied by injecting various objects, each of which can include how to apply these discounts; for example apply discounts only to items that don’t have other discounts, apply discount percentage on the base price not counting already applied discounts, apply discount percentage after other applied discounts, apply a flat amount of a discount for each item, apply a discount on an item based on what type of item it is, etc
  • 23. Strategy pattern • Allow injection of object that provides some aspect of the functionality • Algorithm’s functionality can be decided at run-time • Examples: • usort - Provide comparison part of sort • Car - brakingStrategy
  • 24. Command Pattern • I’m doing a bunch of stuff that I want to be able to keep track of and potentially save and replay later, possibly be able to undo. In order for this to work my object will have to capture everything it needs to know about as far as parameters and what-not in order to be able to run later as well as potentially capturing state so I can get back to where I was before.
  • 25. Command Pattern • Uses: • Recording Macros • Multi-level Undo • Progress Bars • Transactional Behavior • Wizards
  • 26. Chain of Responsibility • Each object can take care of something (or not), then it passes to the next object
  • 27. Chain of Responsibility Examples • Loggers - set next logger in chain, each calls the next when it is done • Managers with purchasing power - if amount is above manager’s level, pass to the next object in the chain
  • 28. Observer Pattern • Notify interested objects of state changes in subject • Interested objects subscribe to subject • When subject changes, it calls update on all observers
  • 29. MVC - Model View Controller • Organizational pattern for web dev • View code contains output • Model code is for data/business logic • Controller links model and view code
  • 30. Front Controller • Central entry point for handling requests for web application • Route all calls through index.php, then figure out what to do with it
  • 31. Adapter Pattern • Allow interface for an existing class to be used from another interface
  • 32. Facade Pattern • Provide simplified access to a complex system
  • 33. Other Patterns • Bridge • Composite • Decorator • Front Controller • Blackboard • Iterator • Mediator • Memento • Null Object • Specification • State • Template Method • Visitor • Abstract Factory • Prototype