Software Design Patterns in Laravel by Phill Sparks

121,403 views

Published on

Laravel makes use of quite a few well-established design patterns that promote reusable object-oriented code. Together, we will investigate the design patterns used in the core of Laravel 4 and discuss how they encourage reusable software.

Published in: Technology, Design
4 Comments
90 Likes
Statistics
Notes
No Downloads
Views
Total views
121,403
On SlideShare
0
From Embeds
0
Number of Embeds
89,796
Actions
Shares
0
Downloads
548
Comments
4
Likes
90
Embeds 0
No embeds

No notes for slide

Software Design Patterns in Laravel by Phill Sparks

  1. 1. Software Design Patterns in Laravel 4 by Phill Sparks
  2. 2. Credits • Rosalind Goodall - Graphics • Taylor Otwell - Laravel
  3. 3. @PhillSparks
  4. 4. @PhillSparks •API Engineer at CrowdLab
  5. 5. @PhillSparks •API Engineer at CrowdLab •From Leicester, UK
  6. 6. @PhillSparks •API Engineer at CrowdLab •From Leicester, UK •Climbing Instructor
  7. 7. @PhillSparks •API Engineer at CrowdLab •From Leicester, UK •Climbing Instructor •Scout
  8. 8. @PhillSparks •API Engineer at CrowdLab •From Leicester, UK •Climbing Instructor •Scout •Laravel Core Team
  9. 9. Laravel • With Laravel since 1.5.9 • Core Team Member • Past: Quality Team • Now: Community engagement and support
  10. 10. Laravel • With Laravel since 1.5.9 • Core Team Member • Past: Quality Team • Now: Community engagement and support • Dayle still owes me 9000 support points!
  11. 11. Software Design Patterns Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice. -- Christopher Alexander, AIS+77 “ ”
  12. 12. Software Design Patterns
  13. 13. Software Design Patterns
  14. 14. The Patterns • Builder • Chain of Responsibility • Command • Facade • Factory • Iterator • Mediator • Observer • Presenter • Repository • Singleton • Strategy
  15. 15. Notations
  16. 16. Class Notations
  17. 17. Sub-class Notations
  18. 18. Abstract Class Notations
  19. 19. Class Instance Notations
  20. 20. Implementation Notations
  21. 21. Building Blocks
  22. 22. Interfaces namespace IlluminateAuth; interface UserInterface { public function getAuthIdentifier(); public function getAuthPassword(); } class GenericUser implements UserInterface {
  23. 23. • 244 interfaces in Laravel (including vendors) • 25 from Laravel Core • 65 from Symfony • 73 from Swiftmailer Interface
  24. 24. Abstract Classes namespace IlluminateDatabaseEloquentRelations; abstract class Relation { abstract public function addConstraints(); abstract public function getResults(); } class BelongsTo extends Relation {
  25. 25. Abstract Classes • 128 abstract classes in Laravel (including vendors) • 14 from Laravel Core • 15 from Swiftmailer • 40 from Symfony
  26. 26. Iterator
  27. 27. PHP’s Iterator Interface
  28. 28. Laravel’s Iterators • Collection • Paginator
  29. 29. Observer
  30. 30. Dispatcher namespace IlluminateEvents;
  31. 31. Dispatcher namespace IlluminateEvents; class LoginHandler { function handle($user) { // do something with $data } } Event::listen(‘user.login’, ‘LoginHandler’); Event::fire(‘user.login’, $user);
  32. 32. Singleton
  33. 33. AliasLoader namespace IlluminateFoundation;
  34. 34. Multiton
  35. 35. DatabaseManager namespace IlluminateDatabase;
  36. 36. Facade
  37. 37. Facade namespace IlluminateSupportFacades;
  38. 38. Input namespace IlluminateSupportFacades;
  39. 39. Route namespace IlluminateSupportFacades;
  40. 40. Response namespace IlluminateSupportFacades;
  41. 41. Str namespace IlluminateSupport;
  42. 42. Facade vs Singleton
  43. 43. Decorator
  44. 44. BootstrapPresenter namespace IlluminatePagination;
  45. 45. BootstrapPresenter namespace IlluminatePagination;
  46. 46. Repository • Examples: • IlluminateCacheRepository • IlluminateConfigRepository
  47. 47. Builder (aka Manager) • Examples: • IlluminateAuthAuthManager • IlluminateCacheCacheManager • IlluminateQueueQueueManager • IlluminateSessionSessionManager
  48. 48. Factory • Examples: • IlluminateDatabaseDatabaseManager • IlluminateDatabaseConnectors ConnectionFactory • IlluminateValidationFactory
  49. 49. Service Provider • Core to Laravel’s IoC • See IlluminateSupportServiceProvider • Examples: • IlluminateAuthAuthServiceProvider • IlluminateHashHashServiceProvider • IlluminateLogLogServiceProvider
  50. 50. Strategy • Examples: • IlluminateCacheStoreInterface • IlluminateConfigLoaderInterface • IlluminateDatabase - Builders & Grammars • IlluminateTranslationLoaderInterface • IlluminateViewViewFinderInterface
  51. 51. s/PhillSparks//

×