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

Model Pollution

Henning Schwentner
November 12, 2024
84

Model Pollution

Henning Schwentner

November 12, 2024
Tweet

Transcript

  1. Separation ofConcerns Starring Directed By Special Appearance Introducing DDD With

    Model Pollution is Bad— What Can I Do about It? A Henning Schwentner Talk An Integrated Banking Example and Information Hiding Architecture Hamburger Dependecy Inversion
  2. @hschwentner (Application) Programming 1. Learn about a domain 2. Build

    a model for it 3. Add technology to build the system: • programming language • UI • database • …
  3. @hschwentner Programming 1. Learn about a domain 2. Build a

    model for it 3. Add technology to build the system: • programming language • UI • database • …
  4. @hschwentner Programming 1. Learn about a domain 2. Build a

    model for it 3. Add technology to build the system: • programming language • UI • database • …
  5. @hschwentner Programming 1. Learn about a domain 2. Build a

    model for it 3. Add technology to build the system: • programming language • UI • database • …
  6. @hschwentner Coupling • thus we build coupling. we couple the

    system to technology • => it’s a good idea to localize that coupling! • => that’s one of the reasons for modularity
  7. @hschwentner Structured Programming Edsger Dijkstra Edgar Dijkstra: Go To Statement

    Considered Harmful callable unit callable unit callable unit 1968
  8. @hschwentner Separation of Concerns Edsger Dijkstra “…study in depth an

    aspect in isolation […], all the time knowing that one is occupying oneself only with one of the aspects.” one aspect in isolation 1974
  9. @hschwentner Separation of Concerns ➢ Single responsibility principle ➢ do

    one thing well ➢ Change because of one reason ➢ Separation of business logic and technical code
  10. @hschwentner Fundamental Theorem of Software Engineering David Wheeler “We can

    solve any problem by introducing an extra level of indirection” “…except for the problem of too many levels of indirection”
  11. @hschwentner Entity Tactical Design Value Object Is it a thing?

    Is it a property of a thing? Can you touch it? Is it identityless? Does it have an identity?
  12. @hschwentner Entity vs. Value − Identity − Life cycle −

    Can be mutable − No identity − Always immutable Contract Map Name Length 12.5 m “John Miller” Entity Value Object
  13. @hschwentner Kinds of Ports − For UI etc. − Methods

    to be called − “from above” − For DB and infrastructure − Interfaces to be implemented − “from below”
  14. @hschwentner Domain The Solution Domain Infrastructure bank transaction Oracle DB

    Infrastructure bank transaction Oracle DB port adapter
  15. @hschwentner The 4 Tenets •The application is built around an

    independent object model •Inner layers define interfaces. Outer layers implement interfaces •Direction of coupling is toward the center •All application core code can be compiled and run separate from infrastructure Jeffrey Palermo
  16. @hschwentner Designed for Testability “All application code can be compiled,

    run, and tested separate from infrastructure” Easy unit tests Plays well with TDD
  17. @hschwentner Architecture Hamburger model repository interface controller use case service

    entity value object view data model repository implementation widget library REST frame- work transaction handling domain library programming language ORM file system access domain event
  18. import javax.persistence.*; @Entity class BankAccount { @Id IBAN iban; @Embedded

    Amount balance; /*...*/ } @Embeddable class Amount { /*...*/ }
  19. import javax.persistence.*; @Entity class BankAccount { @Id IBAN iban; @Embedded

    Amount balance; /*...*/ } When you use this You have to have this …and a default constructor …and you can’t have final fields
  20. import javax.persistence.*; @Entity class BankAccount { @Id final IBAN iban;

    @Embedded Amount balance; /*...*/ } the identity should never change …and it should be initialized at creation, i.e. in the constructor
  21. import jakarta.persistence.*; @Entity class BankAccount { @Id final IBAN iban;

    @Embedded Amount balance; /*...*/ } when someone changes the technology, we have to change the business logic, too
  22. import org.jmolecules.ddd.annotation.*; @Entity class Account { @Identity public final IBAN

    iban; public void deposit(Amount amount) //... public void withdraw(Amount amount) //... }
  23. @hschwentner Domain-Driven Refactorings • Strategic Refactorings • Tactical Refactorings (Against

    Big Ball of Mud) Catalog: https://hschwentner.io/domain-driven-refactorings strategic transformation tactical transformation team-organizational transformation • Socio-Technical • Tactical refactorings (Against Model Anemia)
  24. @hschwentner Bibliography Buschmann, Frank, Regine Meunier, Hans Rohnert, Peter Sommerlad,

    and Michael Stal. Pattern-Oriented Software Architecture Volume 1: A System of Patterns. Hoboken, NJ: Wiley, 1996. Cockburn, Alistair. “Hexagonal Architecture.” January 4, 2005. https://alistair.cockburn.us/hexagonal-architecture/. Dijkstra, Edsger. “Go To Statement Considered Harmful.” Communications of the ACM 11, no. 3 (March 1968): 147–48. Evans, Eric. Domain-Driven Design: Tackling Complexity in the Heart of Software. Boston: Addison-Wesley, 2004. Fowler, Martin. Patterns of Enterprise Application Architecture. Boston: Addison- Wesley, 2005. Gamma, Erich, Richard Helm, Ralph Johnson, and John Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Reading, MA: Addison-Wesley, 1995. Graca, Herberto. “DDD, Hexagonal, Onion, Clean, CQRS, … How I Put It All Together.”