Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Advanced Application Architecture Symfony Live Berlin 2018

1.031 Aufrufe

Veröffentlicht am

Advanced Application Architecture Symfony Live Berlin 2018

Veröffentlicht in: Software
  • Loggen Sie sich ein, um Kommentare anzuzeigen.

Advanced Application Architecture Symfony Live Berlin 2018

  1. 1. ADVANCED APPLICATION ARCHITECTURE I - Layers Matthias Noback @matthiasnoback
  2. 2. MATERIALS ARE ON TWITTER https://twitter.com/ matthiasnoback
  3. 3. matthiasnoback/
 layers-ports-and-adapters- workshop Clone from GitHub docker-compose pull bin/composer.sh install docker-compose up -d
  4. 4. DEMO TIME Navigate to localhost (or localhost:8080)
  5. 5. ARCHITECTURE Decisions about coupling and cohesion
  6. 6. COUPLING How are things linked to each other?
  7. 7. COHESION Which things belong together?
  8. 8. LAYERED ARCHITECTURE An answer to both questions
  9. 9. LAYERS Help you protect what's in a deeper layer
  10. 10. LAYERS Allow you to define dependency rules
  11. 11. LAYERS Define the right place to put things
  12. 12. TRADITIONAL LAYERING MVC view controller model
  13. 13. TRADITIONAL LAYERING Works well with JS view model data
  14. 14. LAYERS Horizontal division (as opposed to...)
  15. 15. USE CASES Vertical division
  16. 16. COHESION A basic set of layers infrastructure application domain
  17. 17. COUPLING The dependency rule Layers should only depend on deeper layers
  18. 18. COUPLING The dependency rule infrastructure application domain
  19. 19. COUPLING Dependency inversion principle Classes should always depend on things that are more abstract
  20. 20. COUPLING Dependency inversion principle low-levelconcrete class specific abstract interface generic high-level
  21. 21. COUPLING Dependency inversion principle use
  22. 22. COUPLING Dependency inversion principle use implement
  23. 23. COUPLING Is about dependencies in code Use Dependency Injection
  24. 24. LAYER CONVENTIONS Domain layer Domain model: ➤ Entities ➤ Value objects ➤ Domain services ➤ Factories Business logic Decisions Data State Behavior
  25. 25. LAYER CONVENTIONS Application layer ➤ Find an object ➤ Change something ➤ Notify something ➤ Get some information Use cases Orchestration
  26. 26. LAYER CONVENTIONS Infrastructure layer Communication with: ➤ HTTP client ➤ Database ➤ Filesystem ➤ Email server ➤ Message broker Connecting the application to the world outside
  27. 27. MATTHIASNOBACK/LAYERS- PORTS-AND-ADAPTERS- WORKSHOP Assignments are on GitHub in assignments/ php -S 0.0.0.0:8080 -t public/
  28. 28. assignment/01.md Layers
  29. 29. ADVANCED APPLICATION ARCHITECTURE II - Ports & adapters
  30. 30. MESSAGING ... is the big idea
  31. 31. PORTS (COHESION) Web, CLI, test client, messages, database queries User interface Persistence
  32. 32. PORTS... AND ADAPTERS Translation HTTP SQL
  33. 33. HEXAGONAL ARCHITECTURE Same thing! User interface Persistence
  34. 34. PORTS... AND ADAPTERS (De)serialization, translation, structural validation HTTP SQL
  35. 35. assignment/02.md Ports
  36. 36. PORT ADAPTERS ...in the Infrastructure layer
  37. 37. APPLICATION SERVICES ... in the Application layer
  38. 38. DOMAIN MODEL in the Domain layer
  39. 39. APPLICATION SERVICES Delivery-mechanism agnostic
  40. 40. assignment/03.md Input adapters
  41. 41. APPLICATION SERVICES Most often they are "command handlers" Command object is a DTO Represents a user's intention Contains primitive-type values
  42. 42. APPLICATION SERVICES Translate, and orchestrate From primitive-type values to rich domain objects Manipulates an entity Persists it May dispatch events
  43. 43. VALIDATION At different levels Structural validation of messages User-friendly input validation Domain invariant protection
  44. 44. STRUCTURAL VALIDATION Infrastructure layer Form keys JSON schema
  45. 45. USER-FRIENDLY INPUT VALIDATION Infrastructure layer Usability concern Prevent problems later on Localized, translated Friendly
  46. 46. DOMAIN INVARIANT PROTECTION Application & Domain layer Domain objects: always valid Valid state Valid state transitions
  47. 47. assignment/04.md Input validation
  48. 48. APPLICATION SERVICES Transactional consistency
  49. 49. assignment/05.md Output adapter
  50. 50. INCOMPLETE ENTITY A Meetup without an ID...
  51. 51. DATABASE-GENERATED ID Faux-auto increment (check out the code)
  52. 52. ALTERNATIVE: UUID Universally Unique Identifier 7d7fd0b2-0cb5-42ac-b697-3f7bfce24df9
  53. 53. assignment/06.md A hidden dependency on the persistence mechanism
  54. 54. ALTERNATIVE: SEQUENCE MeetupId encapsulates the type of ID used
  55. 55. ADVANTAGES OF USING LAYERS, 
 PORTS & ADAPTERS Offers insight into the application Provides a useful convention for the team Isolates the low-level details Allows for alternative implementations Helps with testing
  56. 56. ADVANCED APPLICATION ARCHITECTURE III - Testing
  57. 57. UNIT TESTS Testing your units of code One class at a time No IO No setup required Mocking only dependencies "you own"
  58. 58. INTEGRATION TESTS Testing your adapters Maybe multiple classes Including IO Some setup required Mocking no dependencies
  59. 59. ACCEPTANCE TESTS Testing your application services Multiple classes Use cases Infrastructure stand-ins
  60. 60. SYSTEM TESTS Testing your application end-to-end The real deal
  61. 61. TESTING PYRAMID Make it well-balanced Unit Integration System Acceptance Development Regression
  62. 62. TESTING PYRAMID Make it well-balanced Supports development Prevents regressionSlow, brittle Fast, stable Proof of effectiveness Proof of Correctness
  63. 63. assignment/07.md Different types of tests
  64. 64. ACCEPTANCE TESTS Use infrastructure stand-ins Acceptance test test the application layer
  65. 65. Persistence FileBased InMemory Port Adapters
  66. 66. MeetupRepository FileBasedMeetupRepository InMemoryMeetupRepository Domain Infrastructure implements implements
  67. 67. assignment/08.md A test double for the Persistence port
  68. 68. assignment/09.md An acceptance test for the application layer
  69. 69. A WELL-BALANCED TEST SUITE Adapters can be easily replaced Test suite is fast Feedback is quick Small amount of fragile tests Enables continuous delivery
  70. 70. https://training.matthiasnoback.nl/
  71. 71. Feedback? @matthiasnoback training.matthiasnoback.nl
  72. 72. assignment/10.md Notifications

×