Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Schmutzige Hände mit Clean Architecture (JAX 2019)

Schmutzige Hände mit Clean Architecture (JAX 2019)

Was steckt eigentlich hinter den Begriffen "Clean Architecture" oder "Hexagonal Architecture"? Clean ist immer gut, oder? Sollte ich die mir so ans Herz gewachsene Layerarchitektur vergessen und nur noch Clean Architecture anwenden?

Diese Session gibt einen Überblick über die Konzepte und Ziele hinter Uncle Bob’s Clean Architecure und Co. und stellt Möglichkeiten vor, diese in (Java-)Code umzusetzen. Wir werden diskutieren, wann sich eine Clean Architecture lohnt, welche Abkürzungen man einbauen kann, um den Aufwand im Rahmen zu halten, und wann man lieber die Finger davonlassen sollte.

Bc7aa56e8e004e4984e954e5e4cb2bc0?s=128

Tom Hombergs

May 09, 2019
Tweet

More Decks by Tom Hombergs

Other Decks in Technology

Transcript

  1. Schmutzige Hände mit Clean Architecture Tom Hombergs

  2. Layers

  3. Layers within Verticals

  4. Why bother with Architecture?

  5. Architecture Goals

  6. Architecture Goals

  7. Architecture Goals The goal of software architecture is to minimize

    the lifetime cost of the software
  8. So ... What‘s Wrong With Layers?

  9. Disclaimer Layers are a solid architecture pattern! But without additional

    restrictions they are prone to design flaws
  10. Database-Driven Design

  11. Blurred Boundaries

  12. Hard-to-test Shortcuts

  13. Hidden Functionality

  14. Do Circles Instead!

  15. SOLID Principles S O L I D Single Responsibility Principle

    Open-Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle
  16. Dependency Inversion Principle SOLID Principles S O L I D

    Single Responsibility Principle Open-Closed Principle Liskov Substitution Principle Interface Segregation Principle
  17. Dependency Inversion Principle

  18. Dependency Inversion Principle We can choose the direction of any

    code dependency* * As long as we have control over the code
  19. Clean Architecture (Robert C. Martin)

  20. Single Responsibility Principle Dependency Inversion Principle SOLID Principles S O

    L I D Open-Closed Principle Liskov Substitution Principle Interface Segregation Principle
  21. Single Responsibility Principle

  22. Single Responsibility Principle A module* should have only one reason

    to change * Read: class, package, component, architecture element, software entity, …
  23. Single Responsibility Principle – Macro Level

  24. Single Responsibility Principle – Macro Level

  25. Domain-Driven Design Only a Domain-Centric Architecture allows Domain-Driven Design

  26. Single Responsibility Principle – Micro Level

  27. Single Responsibility Principle – Micro Level

  28. Do Hexagons Instead!

  29. Hexagonal Architecture / Ports & Adapters (Alistair Cockburn)

  30. Choose your Polygonal Style

  31. Use Cases in a Hexagonal Architecture

  32. Quiz: What does this Application do?

  33. Quiz: What does this Application do?

  34. Let‘s Get Our Hands Dirty!

  35. Implementing a Use Case https://github.com/thombergs/clean-architecture-example

  36. Implementing a Persistence Adapter with Spring Boot https://github.com/thombergs/clean-architecture-example

  37. Implementing a Web Adapter with Spring Boot https://github.com/thombergs/clean-architecture-example

  38. Mapping Strategies

  39. Mapping Strategies – Two Way Mapping

  40. Mapping Strategies – No Mapping

  41. Mapping Strategies – Full Mapping

  42. Mapping Strategies – Mix & Match!

  43. Enforcing the Architecture

  44. Enforcing the Architecture - Separate Build Artifacts

  45. Enforcing the Architecture - ArchUnit @Test void validateRegistrationContextArchitecture() { HexagonalArchitecture

    .boundedContext("io.reflectoring.copyeditor.registration") .withDomain("domain") .withAdapters("adapter") .incoming("in.web") .outgoing("out.persistence") .and() .withApplicationLayer("application") .services("book") .services("invitation") .incomingPorts("port.in") .outgoingPorts("port.out") .and() .withConfiguration("configuration") .check(allClasses()); }
  46. Enforcing the Architecture - Java Module System Yes, it will

    probably work … … but I'm used to having 5 years of time to learn each new Java version.
  47. Conclusion

  48. Benefits of a Domain-Centric Architecture

  49. Drawbacks of a Domain-Centric Architecture

  50. Get the e-book for free! https://geni.us/dirty-hands-jax2019 Subscribe my Blog at

    https://reflectoring.io Thanks for your Patience!