SlideShare una empresa de Scribd logo
1 de 41
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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 a 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 a 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
 

Último

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Último (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
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!
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

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