Laravel.IO A Use-Case Architecture

download Laravel.IO A Use-Case Architecture

of 110

Embed Size (px)

description

A simple architecture is perfect for a simple application. But, as the application grows in its complexity, the architecture must become more complex in order to prevent it from becoming unmaintainable. In this talk we discuss some ideas for simplifying complex code bases. We also discuss the important distinctions between presentation, service, and domain layers and strategies for separating high-level business policy from implementation. Some Domain-Driven Design topics are discussed, but this is not a talk about DDD. DDD is not about design patterns, but rather is about business analysis, communication, and much more.

Transcript of Laravel.IO A Use-Case Architecture

  • LARAVEL.IO A USE CASE ARCHITECTURE
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC HI, IM SHAWN
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC LARAVEL.IO ORIGIN
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC Laravel.IO Now LARAVEL.IO FORUM from Nick Spelt and myself LIONA (LioBot) from Sam Evaskitas and Matthew Machuga LARAVEL WEEKLY NEWSLETTER by Dries Vints PODCAST http://bit.ly/laravelio-podcast Assets available for contribution at: https://github.com/LaravelIO
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC AKA ENGINEERING MANAGING COMPLEXITY
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC FUNCTIONAL REQUIREMENTS
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC USE CASES
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC ENTITIES Many objects are not fundamentally defined by their attributes, but rather by a thread of continuity and identity. - Eric Evans
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC PeoplePERSON
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC Jane Doe People Jane Doe PERSON
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC Jane Doe People Jane DoeJane Doe PERSON Jane Doe
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC Jane Doe PERSON Age: 27 Jane Doe Age: 27
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC Jane Doe PERSON Age: 27 From: NYC Jane Doe Age: 27 From: NYC
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC THE ACTIVERECORD PATTERN
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC ID: 1 ID: 2 Jane Doe PERSON Age: 27 From: NYC Jane Doe Age: 27 From: NYC People Table ID 1 2 Age 27 27 From NYC NYC Name Jane Doe Jane Doe
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC ENTITIES AND ACTIVERECORD
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC THIS IS NOT DDD
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC LAYERED ARCHITECTURE
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC A COMMON APPLICATION PRESENTATION LAYER Controllers Artisan Commands Queue Listeners
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC PRESENTATION LAYER Controllers Artisan Commands Queue Listeners DOMAIN Entities Repository Interfaces A COMMON APPLICATION
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC PRESENTATION LAYER Controllers Artisan Commands Queue Listeners SERVICE LAYER Sending Email Queueing up Jobs Repository Implementations DOMAIN Entities Repository Interfaces A COMMON APPLICATION
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC PRESENTATION LAYER Controllers Artisan Commands Queue Listeners SERVICE LAYER Sending Email Queueing up Jobs Repository Implementations Commands / Command Bus DOMAIN Entities Repository Interfaces A COMMON APPLICATION
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC A COMMAND ORIENTED INTERFACE
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC MEAT OF THE APPLICATION WHAT IS A COMMAND
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC Controller Artisan Command Queue Worker Whatever MEAT OF THE APPLICATION WHAT IS A COMMAND
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC WHAT IS A COMMAND MEAT OF THE APPLICATION REGISTER MEMBER COMMAND
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC WHAT IS A COMMAND MEAT OF THE APPLICATION REGISTER MEMBER COMMAND
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC WHAT IS A COMMAND REGISTER MEMBER COMMAND MEAT OF THE APPLICATION
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC Some Advantages - No business policy in your controllers - Your code shows intent - A single dedicated flow per use case - A single point of entry per use case - Easy to see which use cases are implemented
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC COMMAND ANATOMY
  • class RegisterMemberCommand { public $displayName; public $email; public $password; public function __construct($displayName, $email, $password) { $this->displayName = $displayName; $this->email = $email; $this->password = $password; } }
  • class RegisterMemberCommand { public $displayName; public $email; public $password; public function __construct($displayName, $email, $password) { $this->displayName = $displayName; $this->email = $email; $this->password = $password; } }
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC WHAT IS HAPPENING INSIDE? MEAT OF THE APPLICATION REGISTER MEMBER COMMAND
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC THE FINAL DESTINATION MEAT OF THE APPLICATION REGISTER MEMBER HANDLER REGISTER MEMBER COMMAND
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC THE FINAL DESTINATION MEAT OF THE APPLICATION ?REGISTER MEMBER COMMAND REGISTER MEMBER HANDLER
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC THE TRANSPORT MECHANISM MEAT OF THE APPLICATION COMMAND BUSREGISTER MEMBER COMMAND REGISTER MEMBER HANDLER
  • Laravel.IO, A Use Case Architecture By Shawn McCool Laracon 2014 in NYC COMMAND BUS IMPLEMENTATION
  • class ExecutionCommandBus implements CommandBus { private $container; private $mapper; public function __construct(Container $container,Mapper $mapper) { $this->container = $container; $this->mapper = $mapper; } public function execute($command) { $this->getHandler($command)->handle($command); } private function getHandler($command) { $class = $this->mapper->getHandlerClassFor($command); return $this->container->make($class); } }
  • class ExecutionCommandBus implements CommandBus { private $container; private $mapper; public function __construct(Container $container,Mapper $mapper) { $this->container = $container; $this->mapper = $mapper; } public function execute($command) { $this->getHandler($command)->handle($command); } private function getHandler($command) { $class = $this->mapper->getHandlerClassFor($command); return $this->container->make($class); } }
  • class ExecutionCommandBus implements CommandBus { private $container; private $mapper; public function __construct(Container $container,Mapper $mapper) { $this->container = $container; $this->mapper = $mapper; } public function execute($command) { $this->getHandler($command)->handle($command); } private function getHandler($command) { $class = $this->mapper->getHandlerClassFor($command); return $this->container->make($class); } }
  • class ExecutionCommandBus implements CommandBus { private $container; private $mapper; public function __construct(Container $container,Mapper $mapper) { $this->container = $container; $this->mapper = $mapper; } public function execute($command) { $this->getHandler($command)->handle($command); } private function getHandler(