• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Beautiful Models in PHP
 

Beautiful Models in PHP

on

  • 6,763 views

 

Statistics

Views

Total Views
6,763
Views on SlideShare
6,220
Embed Views
543

Actions

Likes
7
Downloads
14
Comments
1

2 Embeds 543

http://www.brandonsavage.net 541
http://www.scoop.it 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Interesting, but how could you suggest to manage joins between models, especially when the data is a DB?
    For example, if we want the list of Customer and PhoneNumber, is convenient to have a single JOIN query instead of 2 queries.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Beautiful Models in PHP Beautiful Models in PHP Presentation Transcript

    • 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 answer1.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 forrepresenting ‘concepts’ (entities) and the relationship between them. (Wikipedia)
    • A model is a method of representing data in a logical way.
    • Friends Blog postsCustomers News stories Sermons Users Clients Political partiesTransactions 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/PostgreSQLREST APIs Amazon Redis Elastic Search Memcache APC MongoDB File system Web services Other web apps
    • What are thecomponents of a model?
    • 1. The thing you’re modeling.
    • Friends Blog postsCustomers News stories Sermons Users Clients Political partiesTransactions Television shows Comments Lovers
    • 2. The place the data is stored.
    • MySQL/PostgreSQLREST APIs Amazon Redis Elastic Search Memcache APC MongoDB File system Web services Other web apps
    • 3. The method forinteracting 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.
    • <?phpclass Customer { ... }<?phpclass PhoneNumber { ... }<?phpclass Account { ... }
    • <?phpclass Customer { protected $phone_numbers = array(); protected $accounts = array(); public function get_phone_numbers() { ... }}<?phpclass Account { protected $customer;}
    • Each value object is populated by the gateway object.
    • Items that can bemodeled 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 andretrieval 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 MasterclassGet 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