SlideShare a Scribd company logo
1 of 41
Download to read offline
Your First 5 PHP Design Patterns
           by Aaron Saray
Why trust this guy?
                  ● 20 years of
                    programming

                  ● MKEPUG

                  ● I wrote the book on
                    this topic

                  ● ... you paid! ;)
Obligatory Slide
● Web Development
  Manager
  ○ Liturgical Publications, Inc.
What we're here to do...
● Talk about what Design Patterns are
    ○ you don't need a comp-sci phd

●   Show you where you've seen them before

●   Introduce 5 design patterns
    ○ real-people-talk descriptions
    ○ code samples

● Q&A
What are Patterns?
What are Design Patterns?
● Solving the same problem over and over
  ○ but the 'right' way

  ○ the old guys got it right

● Why is this important to PHP programmers?
  ○ PHP is easy to get into

  ○ We think we'll save the world, or own it?
    ■ FB is worth billions - and is PHP right?
Software Design has Three Parts
● "What"
  ○ business and functionality

● "How"
  ○ which design you choose

● "Work"
  ○ implementation - or using "how"
Where do Design Patterns fall?
Design Patterns are the "How"




                  They make the "work"
                  less sucky.
This isn't new...
● Non-PHP Programmers have seen this before
  ○ I vaguely remember something from college JAVA

● PHP Guys, you've seen this before
  ○ PEAR DB
  ○ Zend Registry
  ○ Zend URI Factory
  ○ Doctrine DAO
The Godfathers
● Gang of Four
  ○ Erich Gamma
  ○ Richard Helm
  ○ Ralph Johnson
  ○ John Vlissides
What Design Patterns are NOT
● Not Plug n Play code

● You can't blindly copy these

● Unproven theory
  ○ Design Laws?
So, before we go on...
● Solving the same problem over and over
  ○ correctly

● Language agnostic
  ○ but we're going to focus on PHP

● These are not new - you've used them

● GoF

● Not Copy and Paste
Let's do this!
#1 - Singleton Pattern
(purists, stop groaning)



● The Singleton Design Pattern is used to restrict the
       number of times a specific object can be created to a
       single time by providing access to a shared instance of
       itself.

● Why might you use this?
  ○ Db
  ○ Heavy Front Build
  ○ Static Content
#1 continued
● Sometimes 1 instance isn't right...
  ○ could restrict to 5 instances
    ■ pool?

● Was someone next to you groaning?
  ○ "A proper registry of objects do away with this
      pattern. Mrrr mRrrr mrrr! Rabble Rabble!"

   ○ programmers aren't responsible.
Singleton Code
Singleton Code
or... with Abstracts too...
There are many ways to skin a cat...

wait.. what? Poor cat...
Singleton Code
Singleton Code
#2 - Factory Pattern
● The Factory Design Pattern provides a simple interface
   to acquire a new instance of an object while sheltering
   the calling code from the steps to determine which base
   class is actually instantiated.

● Why might we use this?
  ○ Inventory system dealing with types of objects
  ○ View system requesting objects
  ○ Youtube vs Vimeo URL
Factory Code
Factory Code
#3 - Observer Pattern
● The Observer Design pattern facilitates the creation of
   objects that watch the state of a targeted functionality
   that is uncoupled from the core object.

● Why might we use this
  ○ Plugins
  ○ Don't want to modify shared code
  ○ Licensing
  ○ Enable / Disable auxiliary functions
Observer Code
Observer Code
Observer Code
Observer Code
#4 - Decorator Pattern
● The Decorator Design Pattern is best suited for altering
   or "decorating" portions of an existing object's content or
   functionality without modifying the structure of the
   original object.

● Why might we use this?
  ○ quick small changes to internal content / values
  ○ modify user input (filter)
  ○ pretty output
Decorator Code
Decorator Code
Decorator Code
#5 - Strategy Pattern
● The Strategy Design Pattern helps architect an object
   that can make use of algorithms in other objects on
   demand in lieu of containing the logic itself.

● Why might we use this?
  ○ reduce code duplication on similar models
  ○ no re-inventing the wheel
  ○ quickly add a different process without changing the
      base object
      ■ Ex: YouTube changes the URL format
Strategy Code
Strategy Code
Strategy Code
What's next?
● Put this into practice

● Refactor your code / Plan new code

● Learn more design patterns:
  ○ GoF: http://saray.me/KqqHm1
  ○ Me: http://saray.me/JIP98B
Aaron Saray
                         Open Source Developer
                         Milwaukee, WI
Questions?
                             http://aaronsaray.com

● Questions about            @aaronsaray
  PHP Design Patterns?


                         Milwaukee PHP Users Group
                         http://mkepug.org
                         @mkepug

More Related Content

What's hot

Presentatie xPage & Beer
Presentatie xPage & BeerPresentatie xPage & Beer
Presentatie xPage & BeerJeroen Somhorst
 
Prototyping Workshop - Wireframes, Mockups, Prototypes
Prototyping Workshop - Wireframes, Mockups, PrototypesPrototyping Workshop - Wireframes, Mockups, Prototypes
Prototyping Workshop - Wireframes, Mockups, PrototypesMarta Soncodi
 
Behat - human-readable automated testing
Behat - human-readable automated testingBehat - human-readable automated testing
Behat - human-readable automated testingnyccamp
 
Boston Startup School - OO Design
Boston Startup School - OO DesignBoston Startup School - OO Design
Boston Startup School - OO DesignBryan Warner
 
Webdev bootcamp
Webdev bootcampWebdev bootcamp
Webdev bootcampDSCMESCOE
 
Language portfolio
Language portfolioLanguage portfolio
Language portfolioDhaval Dalal
 
Geecon10: Object Oriented for nonbelievers
Geecon10: Object Oriented for nonbelieversGeecon10: Object Oriented for nonbelievers
Geecon10: Object Oriented for nonbelieversBruno Bossola
 
Clean code, Feb 2012
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012cobyst
 
Templates: Where Should Its Elements Be? In the Template or on Another Module?
Templates: Where Should Its Elements Be? In the Template or on Another Module?Templates: Where Should Its Elements Be? In the Template or on Another Module?
Templates: Where Should Its Elements Be? In the Template or on Another Module?OutSystems
 
Metaprogramming Go
Metaprogramming GoMetaprogramming Go
Metaprogramming GoWeng Wei
 
Web development basics (Part-3)
Web development basics (Part-3)Web development basics (Part-3)
Web development basics (Part-3)Rajat Pratap Singh
 
Jak aspekty uporządkują twój kod.
Jak aspekty uporządkują twój kod.Jak aspekty uporządkują twój kod.
Jak aspekty uporządkują twój kod.Future Processing
 
Visual testing using PhantomCss
Visual testing using PhantomCssVisual testing using PhantomCss
Visual testing using PhantomCssvishnu narang
 

What's hot (20)

Presentatie xPage & Beer
Presentatie xPage & BeerPresentatie xPage & Beer
Presentatie xPage & Beer
 
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
 
Prototyping Workshop - Wireframes, Mockups, Prototypes
Prototyping Workshop - Wireframes, Mockups, PrototypesPrototyping Workshop - Wireframes, Mockups, Prototypes
Prototyping Workshop - Wireframes, Mockups, Prototypes
 
Java interfaces design perspective
Java interfaces design perspectiveJava interfaces design perspective
Java interfaces design perspective
 
BDD with Behat
BDD with BehatBDD with Behat
BDD with Behat
 
Behat - human-readable automated testing
Behat - human-readable automated testingBehat - human-readable automated testing
Behat - human-readable automated testing
 
Boston Startup School - OO Design
Boston Startup School - OO DesignBoston Startup School - OO Design
Boston Startup School - OO Design
 
Webdev bootcamp
Webdev bootcampWebdev bootcamp
Webdev bootcamp
 
Language portfolio
Language portfolioLanguage portfolio
Language portfolio
 
Web application
Web applicationWeb application
Web application
 
Geecon10: Object Oriented for nonbelievers
Geecon10: Object Oriented for nonbelieversGeecon10: Object Oriented for nonbelievers
Geecon10: Object Oriented for nonbelievers
 
Clean code, Feb 2012
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012
 
Templates: Where Should Its Elements Be? In the Template or on Another Module?
Templates: Where Should Its Elements Be? In the Template or on Another Module?Templates: Where Should Its Elements Be? In the Template or on Another Module?
Templates: Where Should Its Elements Be? In the Template or on Another Module?
 
Javascript 01 (js)
Javascript 01 (js)Javascript 01 (js)
Javascript 01 (js)
 
Metaprogramming Go
Metaprogramming GoMetaprogramming Go
Metaprogramming Go
 
Web development basics (Part-3)
Web development basics (Part-3)Web development basics (Part-3)
Web development basics (Part-3)
 
Jak aspekty uporządkują twój kod.
Jak aspekty uporządkują twój kod.Jak aspekty uporządkują twój kod.
Jak aspekty uporządkują twój kod.
 
Visual testing using PhantomCss
Visual testing using PhantomCssVisual testing using PhantomCss
Visual testing using PhantomCss
 
Php traits
Php traitsPhp traits
Php traits
 

Viewers also liked

25 php interview questions – codementor
25 php interview questions – codementor25 php interview questions – codementor
25 php interview questions – codementorArc & Codementor
 
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
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK ExamplesEnder Aydin Orak
 
PHP client - Mongo db User Group Pune
PHP client - Mongo db User Group PunePHP client - Mongo db User Group Pune
PHP client - Mongo db User Group PuneNishant Shrivastava
 
Zend Php Certification Study Guide
Zend Php Certification Study GuideZend Php Certification Study Guide
Zend Php Certification Study GuideKamalika Guha Roy
 
Zend PHP 5.3 Demo Certification Test
Zend PHP 5.3 Demo Certification TestZend PHP 5.3 Demo Certification Test
Zend PHP 5.3 Demo Certification TestCarlos Buenosvinos
 
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
 
Top 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and AnswersTop 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and AnswersVineet Kumar Saini
 
Business analysis interview question and answers
Business analysis interview question and answersBusiness analysis interview question and answers
Business analysis interview question and answersGaruda Trainings
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation TutorialLorna Mitchell
 
85 business analyst interview questions and answers
85 business analyst interview questions and answers85 business analyst interview questions and answers
85 business analyst interview questions and answersBusinessAnalyst247
 
Basic design & visual arts (Elements of design)
Basic design & visual arts (Elements of design)Basic design & visual arts (Elements of design)
Basic design & visual arts (Elements of design)Ar.Shakti Nanda
 

Viewers also liked (17)

25 php interview questions – codementor
25 php interview questions – codementor25 php interview questions – codementor
25 php interview questions – codementor
 
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
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK Examples
 
PHP client - Mongo db User Group Pune
PHP client - Mongo db User Group PunePHP client - Mongo db User Group Pune
PHP client - Mongo db User Group Pune
 
Zend Php Certification Study Guide
Zend Php Certification Study GuideZend Php Certification Study Guide
Zend Php Certification Study Guide
 
Zend PHP 5.3 Demo Certification Test
Zend PHP 5.3 Demo Certification TestZend PHP 5.3 Demo Certification Test
Zend PHP 5.3 Demo Certification Test
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
 
Practice exam php
Practice exam phpPractice exam php
Practice exam php
 
1000+ php questions
1000+ php questions1000+ php questions
1000+ php questions
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Top 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and AnswersTop 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and Answers
 
Business analysis interview question and answers
Business analysis interview question and answersBusiness analysis interview question and answers
Business analysis interview question and answers
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
85 business analyst interview questions and answers
85 business analyst interview questions and answers85 business analyst interview questions and answers
85 business analyst interview questions and answers
 
Basic design & visual arts (Elements of design)
Basic design & visual arts (Elements of design)Basic design & visual arts (Elements of design)
Basic design & visual arts (Elements of design)
 

Similar to Your First 5 PHP Design Patterns

Xlab #2: wzorce projektowe
Xlab #2: wzorce projektoweXlab #2: wzorce projektowe
Xlab #2: wzorce projektoweXSolve
 
Everyone hacks design at a hackathon
Everyone hacks   design at a hackathonEveryone hacks   design at a hackathon
Everyone hacks design at a hackathonWillow Brugh
 
Bdd agile requirements
Bdd agile requirementsBdd agile requirements
Bdd agile requirementsAgile Vietnam
 
Meetup 18/10/2018 - Artificiële intelligentie en mobiliteit
Meetup 18/10/2018 - Artificiële intelligentie en mobiliteitMeetup 18/10/2018 - Artificiële intelligentie en mobiliteit
Meetup 18/10/2018 - Artificiële intelligentie en mobiliteitDigipolis Antwerpen
 
Beginner's Guide to Frontend Development: Comparing Angular, React, Ember, an...
Beginner's Guide to Frontend Development: Comparing Angular, React, Ember, an...Beginner's Guide to Frontend Development: Comparing Angular, React, Ember, an...
Beginner's Guide to Frontend Development: Comparing Angular, React, Ember, an...Prasid Pathak
 
Professional development
Professional developmentProfessional development
Professional developmentJulio Martinez
 
Fundamentals of App & Web Design
Fundamentals of App & Web DesignFundamentals of App & Web Design
Fundamentals of App & Web DesignVishal Kirti
 
Deep Learning Applications (dadada2017)
Deep Learning Applications (dadada2017)Deep Learning Applications (dadada2017)
Deep Learning Applications (dadada2017)Abhishek Thakur
 
2024.04 - AI in Code Generation - April User Group Meeting
2024.04 - AI in Code Generation - April User Group Meeting2024.04 - AI in Code Generation - April User Group Meeting
2024.04 - AI in Code Generation - April User Group Meetingpetercaitens1
 
WordCamp Milwaukee 2012 - Aaron Saray - Secure Wordpress Coding
WordCamp Milwaukee 2012 - Aaron Saray - Secure Wordpress CodingWordCamp Milwaukee 2012 - Aaron Saray - Secure Wordpress Coding
WordCamp Milwaukee 2012 - Aaron Saray - Secure Wordpress CodingAaron Saray
 
Getting started contributing to Apache Spark
Getting started contributing to Apache SparkGetting started contributing to Apache Spark
Getting started contributing to Apache SparkHolden Karau
 
Open source, What | Why | How
Open source, What | Why | How Open source, What | Why | How
Open source, What | Why | How Nikhil Agrawal
 
Software Engineering Primer
Software Engineering PrimerSoftware Engineering Primer
Software Engineering PrimerGeorg Buske
 
Failing the coding interview
Failing the coding interviewFailing the coding interview
Failing the coding interviewSoohan Ahn
 
Enterprise PHP Architecture through Design Patterns and Modularization (Midwe...
Enterprise PHP Architecture through Design Patterns and Modularization (Midwe...Enterprise PHP Architecture through Design Patterns and Modularization (Midwe...
Enterprise PHP Architecture through Design Patterns and Modularization (Midwe...Aaron Saray
 
Why no one is looking for rockstar programmers (updated version)
Why no one is looking for rockstar programmers (updated version)Why no one is looking for rockstar programmers (updated version)
Why no one is looking for rockstar programmers (updated version)Wiktor Schmidt
 
Design of everyday things fundamental principles of interaction - V2
Design of everyday things   fundamental principles of interaction - V2Design of everyday things   fundamental principles of interaction - V2
Design of everyday things fundamental principles of interaction - V2Isaac Liao
 
Sharpening the Axe
Sharpening the AxeSharpening the Axe
Sharpening the AxeMediacurrent
 

Similar to Your First 5 PHP Design Patterns (20)

Xlab #2: wzorce projektowe
Xlab #2: wzorce projektoweXlab #2: wzorce projektowe
Xlab #2: wzorce projektowe
 
Everyone hacks design at a hackathon
Everyone hacks   design at a hackathonEveryone hacks   design at a hackathon
Everyone hacks design at a hackathon
 
Bdd agile requirements
Bdd agile requirementsBdd agile requirements
Bdd agile requirements
 
Meetup 18/10/2018 - Artificiële intelligentie en mobiliteit
Meetup 18/10/2018 - Artificiële intelligentie en mobiliteitMeetup 18/10/2018 - Artificiële intelligentie en mobiliteit
Meetup 18/10/2018 - Artificiële intelligentie en mobiliteit
 
Beginner's Guide to Frontend Development: Comparing Angular, React, Ember, an...
Beginner's Guide to Frontend Development: Comparing Angular, React, Ember, an...Beginner's Guide to Frontend Development: Comparing Angular, React, Ember, an...
Beginner's Guide to Frontend Development: Comparing Angular, React, Ember, an...
 
Create your library
Create your libraryCreate your library
Create your library
 
Professional development
Professional developmentProfessional development
Professional development
 
Fundamentals of App & Web Design
Fundamentals of App & Web DesignFundamentals of App & Web Design
Fundamentals of App & Web Design
 
Deep Learning Applications (dadada2017)
Deep Learning Applications (dadada2017)Deep Learning Applications (dadada2017)
Deep Learning Applications (dadada2017)
 
Coding dojo
Coding dojoCoding dojo
Coding dojo
 
2024.04 - AI in Code Generation - April User Group Meeting
2024.04 - AI in Code Generation - April User Group Meeting2024.04 - AI in Code Generation - April User Group Meeting
2024.04 - AI in Code Generation - April User Group Meeting
 
WordCamp Milwaukee 2012 - Aaron Saray - Secure Wordpress Coding
WordCamp Milwaukee 2012 - Aaron Saray - Secure Wordpress CodingWordCamp Milwaukee 2012 - Aaron Saray - Secure Wordpress Coding
WordCamp Milwaukee 2012 - Aaron Saray - Secure Wordpress Coding
 
Getting started contributing to Apache Spark
Getting started contributing to Apache SparkGetting started contributing to Apache Spark
Getting started contributing to Apache Spark
 
Open source, What | Why | How
Open source, What | Why | How Open source, What | Why | How
Open source, What | Why | How
 
Software Engineering Primer
Software Engineering PrimerSoftware Engineering Primer
Software Engineering Primer
 
Failing the coding interview
Failing the coding interviewFailing the coding interview
Failing the coding interview
 
Enterprise PHP Architecture through Design Patterns and Modularization (Midwe...
Enterprise PHP Architecture through Design Patterns and Modularization (Midwe...Enterprise PHP Architecture through Design Patterns and Modularization (Midwe...
Enterprise PHP Architecture through Design Patterns and Modularization (Midwe...
 
Why no one is looking for rockstar programmers (updated version)
Why no one is looking for rockstar programmers (updated version)Why no one is looking for rockstar programmers (updated version)
Why no one is looking for rockstar programmers (updated version)
 
Design of everyday things fundamental principles of interaction - V2
Design of everyday things   fundamental principles of interaction - V2Design of everyday things   fundamental principles of interaction - V2
Design of everyday things fundamental principles of interaction - V2
 
Sharpening the Axe
Sharpening the AxeSharpening the Axe
Sharpening the Axe
 

Recently uploaded

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Recently uploaded (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

Your First 5 PHP Design Patterns

  • 1. Your First 5 PHP Design Patterns by Aaron Saray
  • 2.
  • 3. Why trust this guy? ● 20 years of programming ● MKEPUG ● I wrote the book on this topic ● ... you paid! ;)
  • 4. Obligatory Slide ● Web Development Manager ○ Liturgical Publications, Inc.
  • 5. What we're here to do... ● Talk about what Design Patterns are ○ you don't need a comp-sci phd ● Show you where you've seen them before ● Introduce 5 design patterns ○ real-people-talk descriptions ○ code samples ● Q&A
  • 7. What are Design Patterns? ● Solving the same problem over and over ○ but the 'right' way ○ the old guys got it right ● Why is this important to PHP programmers? ○ PHP is easy to get into ○ We think we'll save the world, or own it? ■ FB is worth billions - and is PHP right?
  • 8. Software Design has Three Parts ● "What" ○ business and functionality ● "How" ○ which design you choose ● "Work" ○ implementation - or using "how"
  • 9. Where do Design Patterns fall?
  • 10. Design Patterns are the "How" They make the "work" less sucky.
  • 11. This isn't new... ● Non-PHP Programmers have seen this before ○ I vaguely remember something from college JAVA ● PHP Guys, you've seen this before ○ PEAR DB ○ Zend Registry ○ Zend URI Factory ○ Doctrine DAO
  • 12. The Godfathers ● Gang of Four ○ Erich Gamma ○ Richard Helm ○ Ralph Johnson ○ John Vlissides
  • 13.
  • 14. What Design Patterns are NOT ● Not Plug n Play code ● You can't blindly copy these ● Unproven theory ○ Design Laws?
  • 15. So, before we go on... ● Solving the same problem over and over ○ correctly ● Language agnostic ○ but we're going to focus on PHP ● These are not new - you've used them ● GoF ● Not Copy and Paste
  • 17. #1 - Singleton Pattern (purists, stop groaning) ● The Singleton Design Pattern is used to restrict the number of times a specific object can be created to a single time by providing access to a shared instance of itself. ● Why might you use this? ○ Db ○ Heavy Front Build ○ Static Content
  • 18. #1 continued ● Sometimes 1 instance isn't right... ○ could restrict to 5 instances ■ pool? ● Was someone next to you groaning? ○ "A proper registry of objects do away with this pattern. Mrrr mRrrr mrrr! Rabble Rabble!" ○ programmers aren't responsible.
  • 21. or... with Abstracts too... There are many ways to skin a cat... wait.. what? Poor cat...
  • 24. #2 - Factory Pattern ● The Factory Design Pattern provides a simple interface to acquire a new instance of an object while sheltering the calling code from the steps to determine which base class is actually instantiated. ● Why might we use this? ○ Inventory system dealing with types of objects ○ View system requesting objects ○ Youtube vs Vimeo URL
  • 27. #3 - Observer Pattern ● The Observer Design pattern facilitates the creation of objects that watch the state of a targeted functionality that is uncoupled from the core object. ● Why might we use this ○ Plugins ○ Don't want to modify shared code ○ Licensing ○ Enable / Disable auxiliary functions
  • 32. #4 - Decorator Pattern ● The Decorator Design Pattern is best suited for altering or "decorating" portions of an existing object's content or functionality without modifying the structure of the original object. ● Why might we use this? ○ quick small changes to internal content / values ○ modify user input (filter) ○ pretty output
  • 36. #5 - Strategy Pattern ● The Strategy Design Pattern helps architect an object that can make use of algorithms in other objects on demand in lieu of containing the logic itself. ● Why might we use this? ○ reduce code duplication on similar models ○ no re-inventing the wheel ○ quickly add a different process without changing the base object ■ Ex: YouTube changes the URL format
  • 40. What's next? ● Put this into practice ● Refactor your code / Plan new code ● Learn more design patterns: ○ GoF: http://saray.me/KqqHm1 ○ Me: http://saray.me/JIP98B
  • 41. Aaron Saray Open Source Developer Milwaukee, WI Questions? http://aaronsaray.com ● Questions about @aaronsaray PHP Design Patterns? Milwaukee PHP Users Group http://mkepug.org @mkepug