SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Beautiful Models In PHP
       By Brandon Savage
Do your models look like this?
You never wanted your
 code to look this way.


      Let’s fix it.
Who am I?
•   Software engineer at
    Mozilla.

•   Blogger, speaker, author
    of Mastering Object
    Oriented PHP

•   Instrument rated private
    pilot.
Questions we’ll answer
1.What is a model?
2.What are the components of a model?
3.How do you design a model?
4.What parts of an app belong in a model?
5.What parts of an app do not belong in a
  model?

           (last bullet slide I swear!)
What is a model?
(Conceptual) Model - a method for
representing ‘concepts’ (entities) and the
 relationship between them. (Wikipedia)
A model is a method of
 representing data in a
      logical way.
Friends
                                           Blog posts
Customers
                         News stories

        Sermons                         Users

               Clients
                                    Political parties
Transactions

                     Television shows
                                         Comments
               Lovers
Sometimes models map directly to
       a database table.


    A lot of times they don’t.
Models != Database
      Tables
In fact, models may not
 have databases at all.
MySQL/PostgreSQL
REST APIs
                   Amazon
                                  Redis
  Elastic Search

                   Memcache
    APC                               MongoDB


                        File system
   Web services
                                      Other web apps
What are the
components of a model?
1. The thing you’re
     modeling.
Friends
                                           Blog posts
Customers
                         News stories

        Sermons                         Users

               Clients
                                    Political parties
Transactions

                     Television shows
                                         Comments
               Lovers
2. The place the data is
        stored.
MySQL/PostgreSQL
REST APIs
                   Amazon
                                  Redis
  Elastic Search

                   Memcache
    APC                               MongoDB


                        File system
   Web services
                                      Other web apps
3. The method for
interacting with these
      two items.
Domain modeling
Single responsibility
      principle
How do you design a
     model?
Start with a question:
what am I modeling?
Bank customers have
     accounts.


They also have phone
      numbers.
<?php

class Customer { ... }




<?php

class PhoneNumber { ... }




<?php

class Account { ... }
<?php

class Customer {
  protected $phone_numbers = array();
  protected $accounts = array();

    public function get_phone_numbers() { ... }

}




<?php

class Account {

    protected $customer;

}
Each value object is
 populated by the
  gateway object.
Items that can be
modeled individually
    should be.
Items that are too small
  to model individually
      shouldn’t be.
What parts of an app
 belong in a model?
Data storage and
retrieval operations
Business logic
Validation logic
What parts of an app
 do not belong in a
      model?
Display logic
Object creation
Data passing and
   collection
Want to learn more?
              Stop struggling with
              object oriented PHP.
              Start mastering it
              instead.
              DC PHP members get 10% off!
              Use DCPHP10 at checkout.


www.masteringobjectorientedphp.com
The Object Oriented
      PHP Masterclass
Get hands on experience using what you just learned.

        Coming in March. Seats are limited!

      Sign up for updates at brandonsavage.net
Questions?

•   Email: brandon@brandonsavage.net

•   Twitter: @brandonsavage

•   Website: http://www.brandonsavage.net

Weitere ähnliche Inhalte

Ähnlich wie Beautiful Models in PHP

Serverless Machine Learning
Serverless Machine LearningServerless Machine Learning
Serverless Machine LearningAsavari Tayal
 
Why there is no future for Model Driven Development
Why there is no future for Model Driven DevelopmentWhy there is no future for Model Driven Development
Why there is no future for Model Driven DevelopmentJohan den Haan
 
MongoDB World 2019: MongoDB in Data Science: How to Build a Scalable Product ...
MongoDB World 2019: MongoDB in Data Science: How to Build a Scalable Product ...MongoDB World 2019: MongoDB in Data Science: How to Build a Scalable Product ...
MongoDB World 2019: MongoDB in Data Science: How to Build a Scalable Product ...MongoDB
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstEnea Gabriel
 
Social Media Data Collection & Analysis
Social Media Data Collection & AnalysisSocial Media Data Collection & Analysis
Social Media Data Collection & AnalysisScott Sanders
 
Design and Develop Serverless Applications as Set-Pieces
Design and Develop Serverless Applications as Set-PiecesDesign and Develop Serverless Applications as Set-Pieces
Design and Develop Serverless Applications as Set-PiecesSheenBrisals
 
Lessons learned in building a model driven software factory
Lessons learned in building a model driven software factoryLessons learned in building a model driven software factory
Lessons learned in building a model driven software factoryJohan den Haan
 
MongoDB Schema Design by Examples
MongoDB Schema Design by ExamplesMongoDB Schema Design by Examples
MongoDB Schema Design by ExamplesHadi Ariawan
 
Feature store: Solving anti-patterns in ML-systems
Feature store: Solving anti-patterns in ML-systemsFeature store: Solving anti-patterns in ML-systems
Feature store: Solving anti-patterns in ML-systemsAndrzej Michałowski
 
Yurii Pashchenko: Tips and tricks for building your own automated visual data...
Yurii Pashchenko: Tips and tricks for building your own automated visual data...Yurii Pashchenko: Tips and tricks for building your own automated visual data...
Yurii Pashchenko: Tips and tricks for building your own automated visual data...Lviv Startup Club
 
Career_camp_professionals.pdf
Career_camp_professionals.pdfCareer_camp_professionals.pdf
Career_camp_professionals.pdfPrajyotSwami2
 
Web Usability in the Enterprise with Ajax
Web Usability in the Enterprise with AjaxWeb Usability in the Enterprise with Ajax
Web Usability in the Enterprise with AjaxAndreCharland
 
Kamon Ayeva Antipatterns, Patterns, And Rules Of Thumb For Successful Plone...
Kamon Ayeva   Antipatterns, Patterns, And Rules Of Thumb For Successful Plone...Kamon Ayeva   Antipatterns, Patterns, And Rules Of Thumb For Successful Plone...
Kamon Ayeva Antipatterns, Patterns, And Rules Of Thumb For Successful Plone...Vincenzo Barone
 
Resume_Rahul_Gavade
Resume_Rahul_GavadeResume_Rahul_Gavade
Resume_Rahul_GavadeRahul Gavade
 
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...Karen Thompson
 
Learning Web Development with Ruby on Rails Launch
Learning Web Development with Ruby on Rails LaunchLearning Web Development with Ruby on Rails Launch
Learning Web Development with Ruby on Rails LaunchThiam Hock Ng
 

Ähnlich wie Beautiful Models in PHP (20)

Serverless Machine Learning
Serverless Machine LearningServerless Machine Learning
Serverless Machine Learning
 
Recsys 2016
Recsys 2016Recsys 2016
Recsys 2016
 
Why there is no future for Model Driven Development
Why there is no future for Model Driven DevelopmentWhy there is no future for Model Driven Development
Why there is no future for Model Driven Development
 
MongoDB World 2019: MongoDB in Data Science: How to Build a Scalable Product ...
MongoDB World 2019: MongoDB in Data Science: How to Build a Scalable Product ...MongoDB World 2019: MongoDB in Data Science: How to Build a Scalable Product ...
MongoDB World 2019: MongoDB in Data Science: How to Build a Scalable Product ...
 
TechDayPakistan-Slides RAG with Cosmos DB.pptx
TechDayPakistan-Slides RAG with Cosmos DB.pptxTechDayPakistan-Slides RAG with Cosmos DB.pptx
TechDayPakistan-Slides RAG with Cosmos DB.pptx
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
Social Media Data Collection & Analysis
Social Media Data Collection & AnalysisSocial Media Data Collection & Analysis
Social Media Data Collection & Analysis
 
Design and Develop Serverless Applications as Set-Pieces
Design and Develop Serverless Applications as Set-PiecesDesign and Develop Serverless Applications as Set-Pieces
Design and Develop Serverless Applications as Set-Pieces
 
Lessons learned in building a model driven software factory
Lessons learned in building a model driven software factoryLessons learned in building a model driven software factory
Lessons learned in building a model driven software factory
 
MongoDB Schema Design by Examples
MongoDB Schema Design by ExamplesMongoDB Schema Design by Examples
MongoDB Schema Design by Examples
 
Feature store: Solving anti-patterns in ML-systems
Feature store: Solving anti-patterns in ML-systemsFeature store: Solving anti-patterns in ML-systems
Feature store: Solving anti-patterns in ML-systems
 
Yurii Pashchenko: Tips and tricks for building your own automated visual data...
Yurii Pashchenko: Tips and tricks for building your own automated visual data...Yurii Pashchenko: Tips and tricks for building your own automated visual data...
Yurii Pashchenko: Tips and tricks for building your own automated visual data...
 
Career_camp_professionals.pdf
Career_camp_professionals.pdfCareer_camp_professionals.pdf
Career_camp_professionals.pdf
 
AI & AWS DeepComposer
AI & AWS DeepComposerAI & AWS DeepComposer
AI & AWS DeepComposer
 
Web Usability in the Enterprise with Ajax
Web Usability in the Enterprise with AjaxWeb Usability in the Enterprise with Ajax
Web Usability in the Enterprise with Ajax
 
Kamon Ayeva Antipatterns, Patterns, And Rules Of Thumb For Successful Plone...
Kamon Ayeva   Antipatterns, Patterns, And Rules Of Thumb For Successful Plone...Kamon Ayeva   Antipatterns, Patterns, And Rules Of Thumb For Successful Plone...
Kamon Ayeva Antipatterns, Patterns, And Rules Of Thumb For Successful Plone...
 
Resume_Rahul_Gavade
Resume_Rahul_GavadeResume_Rahul_Gavade
Resume_Rahul_Gavade
 
RavenDB overview
RavenDB overviewRavenDB overview
RavenDB overview
 
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
 
Learning Web Development with Ruby on Rails Launch
Learning Web Development with Ruby on Rails LaunchLearning Web Development with Ruby on Rails Launch
Learning Web Development with Ruby on Rails Launch
 

Kürzlich hochgeladen

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
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
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Kürzlich hochgeladen (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Beautiful Models in PHP