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

Domain-Driven Transformation

Domain-Driven Transformation

Henning Schwentner

June 09, 2023
Tweet

More Decks by Henning Schwentner

Other Decks in Programming

Transcript

  1. Starring
    Directed By
    Special
    Appearance
    Presented by
    Photo: Hackercatxxy/Wikipedia

    View Slide

  2. View Slide

  3. THE NAME OF THIS SPEAKER IS HENNING SCHWENTNER
    LIVE 45 MIN TALK

    View Slide

  4. !"#
    Kolleg:in gesucht
    (Deutschlandweit)

    View Slide

  5. View Slide

  6. @hschwentner

    View Slide

  7. @hschwentner
    Alphorn
    Auto Leasing Inc.

    View Slide

  8. @hschwentner

    View Slide

  9. @hschwentner

    View Slide

  10. Monolease A

    View Slide

  11. salesperson
    [person]
    Monolease
    [software system]
    Central car leasing tool
    customer
    [external person]
    risk manager
    [person]
    closes leasing
    contracts with
    creates and
    calculates contracts in
    assesses risk of
    contracts in
    Alphorn Auto Leasing Inc.
    [enterprise]
    Context

    View Slide

  12. @hschwentner
    Alphorn’s boss:
    “Modernize it!”

    View Slide

  13. @hschwentner
    Diagnosis:
    From Which Diseases Does
    Our Patient suffer?

    View Slide

  14. @hschwentner
    Different diseases require
    different treatment

    View Slide

  15. @hschwentner
    big ball
    of mud
    anemic
    domain model
    bad
    team
    organization
    Typical Diseases of
    Legacy Systems

    View Slide

  16. @hschwentner
    big ball
    of mud
    anemic
    domain model
    bad
    team
    organization
    Cures
    strategic
    transformation
    tactical
    transformation socio-technical
    transformation

    View Slide

  17. @hschwentner
    Domain-Driven
    Refactorings
    • Strategic
    • Socio-Technical
    • Tactical (Against Model Anemia)
    • Tactical (Against Big Ball of Mud)
    Catalog:
    https://hschwentner.io/domain-driven-refactorings

    View Slide

  18. @hschwentner
    Strategic

    View Slide

  19. @hschwentner
    Strategic Transformation
    1. Step: Domain re-discovery
    2. Step: Modeling the to-be
    3. Step: Aligning as-is with to-be
    4. Step: Do the move
    RISK
    MANAGE-
    MENT
    SALES

    View Slide

  20. @hschwentner
    Controlling Complexity
    as Key to
    Modernization

    View Slide

  21. “The most
    fundamental problem
    in software
    development is
    complexity. ”
    Bjarne Stroustrup

    View Slide

  22. Controlling
    complexity is
    the essence of
    computer
    programming
    Brian
    Kernighan

    View Slide

  23. “There is only one
    basic way of dealing
    with complexity:
    divide and conquer.”
    Bjarne Stroustrup

    View Slide

  24. View Slide

  25. View Slide

  26. @hschwentner
    Too big
    to be understood
    as a whole

    View Slide

  27. Photo: Henning Schwentner

    View Slide

  28. View Slide

  29. @hschwentner
    How to Modernize
    IT Infratructure?

    View Slide

  30. @hschwentner
    Replace or
    Transform

    View Slide

  31. old old old old
    new
    new new new
    “just flip
    the lever”
    1 2 3 4 5
    a.k.a.
    big bang
    replacement

    View Slide

  32. old old old
    new
    new new new
    2 3 4 5
    old
    1

    View Slide

  33. Strangler
    Fig
    Application
    Photo: Henning Schwentner

    View Slide

  34. Strangler Fig Application

    View Slide

  35. Lesson:
    is better than
    Strangler Fig
    Application
    Big Bang
    Replacement

    View Slide

  36. =>
    bounded
    contexts
    monolith
    buy
    to
    carve out
    build
    new

    View Slide

  37. @hschwentner
    Step 1:
    Domain Re-Discovery

    View Slide

  38. @hschwentner
    To split the monolith
    we first have to
    put it aside

    View Slide

  39. @hschwentner
    Mindset Switch

    View Slide

  40. thinking
    about
    business
    =>
    thinking
    about
    technology
    to

    View Slide

  41. Collaborative Modeling

    View Slide

  42. Collaborative Modeling

    View Slide

  43. customer
    tells wish for
    1
    salesperson
    signs
    to
    gives
    for
    contract
    3
    risk manager
    contract
    passes on
    to
    4
    contract
    votes
    checks
    calculates
    5
    6
    7
    calculates
    to
    8
    2
    car
    credit
    rating
    installment
    car
    resale
    value
    contract

    View Slide

  44. https://hschwentner.io
    Read on in:

    View Slide

  45. @hschwentner
    Step 2:
    Determining the
    To-Be Architecture

    View Slide

  46. @hschwentner
    Drawing Boundaries

    View Slide

  47. @hschwentner
    Scope:
    coarse-grained
    to-be (optimized)
    pure

    View Slide

  48. Which activities
    belong together
    (from an actor’s
    perspective)?

    View Slide

  49. customer
    tells wish for
    1
    salesperson
    signs
    to
    gives
    for
    contract
    3
    risk manager
    contract
    passes on
    to
    4
    contract
    votes
    checks
    calculates
    5
    6
    7
    calculates
    to
    8
    2
    car
    credit
    rating
    installment
    car
    resale
    value
    contract
    sales
    risk assessment

    View Slide

  50. Sales
    Risk
    assessment

    View Slide

  51. @hschwentner
    Step 3:
    Aligning As-Is with To-Be

    View Slide

  52. salesperson
    [person]
    Monolease
    [software system]
    Central car leasing tool
    customer
    [external person]
    risk manager
    [person]
    closes leasing
    contracts with
    creates and
    calculates contracts in
    assesses risk of
    contracts in
    Alphorn Auto Leasing Inc.
    [enterprise]
    Context
    again

    View Slide

  53. salesperson
    [person]
    backend
    [container: EJB 2]
    risk manager
    [person]
    creates and
    calculates contracts in
    assesses risk of
    contracts in
    Monolease
    [software system]
    frontend
    [container: servlets, JSPs]
    database
    [container: IBM DB2]
    Containers

    View Slide

  54. Calculator
    [component]
    frontend
    [container]
    LeasingServlet
    [component: servlet]
    CONTRACTS
    [database table]
    PartnerServlet
    [component: servlet]
    ContractService
    [component]
    PartnerService
    [component]
    backend
    [container]
    database
    [container]
    Contract
    [component]
    Partner
    [component]
    PARTNERS
    [database table]
    Components

    View Slide

  55. big ball
    of mud
    =>
    no vertical
    structuring

    View Slide

  56. Calculator
    [component]
    frontend
    [container]
    LeasingServlet
    [component: servlet]
    CONTRACTS
    [database table]
    PartnerServlet
    [component: servlet]
    ContractService
    [component]
    PartnerService
    [component]
    backend
    [container]
    database
    [container]
    Contract
    [component]
    Partner
    [component]
    PARTNERS
    [database table]
    Components

    View Slide

  57. Calculator
    [component]
    ContractService
    [component]
    PartnerService
    [component]
    backend
    [container]
    Contract
    [component]
    Partner
    [component]
    Component Backend

    View Slide

  58. Calculator
    [component]
    ContractService
    [component]
    PartnerService
    [component]
    Contract
    [component]
    Partner
    [component]
    Component Bounded
    Contexts
    Sales
    Risk Assessment

    View Slide

  59. Calculator
    [component]
    ContractService
    [component]
    PartnerService
    [component]
    Contract
    [component] Partner
    [component]
    Sales
    Risk Assessment
    Contract
    [component]
    Partner
    [component]
    Duplication?

    View Slide

  60. ContractService
    [component]
    Contract
    [component]
    Component Backend
    Sales
    Risk
    assessment

    View Slide

  61. ContractService
    signContract()
    voteContract()
    Code
    Contract
    getContractNumber()
    setSignatureDate()
    setCreditRa7ng()
    setVo7ngResult()
    Sales Risk Assessment

    View Slide

  62. ContractService
    signContract()
    voteContract()
    Code
    Contract
    getContractNumber()
    setSignatureDate()
    setCreditRating()
    setVotingResult()
    Sales Risk Assessment
    ContractService
    signContract()
    voteContract()
    Contract
    getContractNumber()
    setSignatureDate()
    setCreditRating()
    setVotingResult()

    View Slide

  63. ContractService
    signContract()
    Code
    Contract
    getContractNumber()
    setSignatureDate()
    Sales Risk Assessment
    ContractService
    voteContract()
    Contract
    getContractNumber()
    setCreditRa7ng()
    setVo7ngResult()

    View Slide

  64. ContractService
    signContract()
    Code
    Contract
    getContractNumber()
    setSignatureDate()
    Sales Risk Assessment
    ContractService
    voteContract()
    Contract
    getContractNumber()
    setCreditRating()
    setVotingResult()

    View Slide

  65. @hschwentner
    1.2 Extract
    Specialized
    “Contract
    Service”
    1.1 Extract
    Specialized
    “Contract”
    1 Extract
    Context
    “Sales”
    Transformation Backlog
    2 Extract
    Context
    “Risk
    assessment”
    2.1 Extract
    Specialized
    “Contract
    Service”
    2.1 Extract
    Specialized
    “Contract”

    View Slide

  66. @hschwentner
    Insertion:
    Domain-Driven
    Refactorings

    View Slide

  67. @hschwentner
    Domain-Driven
    Refactorings
    • Strategic
    • Socio-Technical
    • Tactical (Against Model Anemia)
    • Tactical (Against Big Ball of Mud)

    View Slide

  68. @hschwentner
    Strategic DDRs
    • Extract Bounded Context
    • Implement Bounded Context from Scratch

    View Slide

  69. @hschwentner
    Tactical DDRs
    (to Support Strategic)
    • Extract Specialized Entity
    • Extract Specialized Anemic Entity
    • Extract Specialized Service
    • Extract Specialized Data Model

    View Slide

  70. @hschwentner
    Extract Bounded Context
    Mechanics
    • Analyze the domain to find out which bounded contexts should be there.
    • Identify a carve-out candidate context
    • Create an empty package/namespace/module for the to-be carved out context besides the big ball of
    mud.
    • Apply the Tactical (to Support Strategic) refactorings that are right for your situation.

    View Slide

  71. @hschwentner
    Extract Specialized
    Anemic Entity
    Mechanics
    • Create empty new class in carved-out context
    • Add instance field of type new class to the old class
    • Copy to-be-moved fields from old to new class => Move Field
    • Copy first to-be-moved method to new class => Move Method
    • Replace method body in old class with a forward to method in new class
    • Step by step replace calls to the method in the old class with calls to the method in the new class
    • Delete the implementation in the old class
    • Delete now unused fields in old class
    • Repeat with other to-be-moved methods
    • Remove instance field of type new class in the old class

    View Slide

  72. Read on at:
    https://hschwentner.io/domain-driven-refactorings

    View Slide

  73. @hschwentner
    Step 4:
    Do the Move

    View Slide

  74. @hschwentner
    Transformation Backlog
    Planning Transformation
    Tactical
    Refactoring 1.2
    Strategic
    Refactoring 1
    User Story A
    Product Backlog
    User Story E
    User Story B
    User Story C
    User Story D
    Tactical
    Refactoring 1.3
    Tactical
    Refactoring 1.4
    Tactical
    Refactoring 2.1
    Strategic
    Refactoring 2
    Sprint Backlog

    View Slide

  75. @hschwentner
    Transformation Backlog
    Planning Transformation
    Tactical
    Refactoring 1.2
    Strategic
    Refactoring 1
    User Story A
    Product Backlog
    User Story E
    User Story B
    User Story C
    User Story D
    Tactical
    Refactoring 1.3
    Tactical
    Refactoring 1.4
    Tactical
    Refactoring 2.1
    Strategic
    Refactoring 2
    Sprint Backlog

    View Slide

  76. @hschwentner
    Transformation Backlog
    Planning Transformation
    Strategic
    Refactoring 1
    Product Backlog
    User Story E
    User Story C
    User Story D
    Tactical
    Refactoring 1.4
    Tactical
    Refactoring 2.1
    Strategic
    Refactoring 2
    Sprint Backlog

    View Slide

  77. @hschwentner
    Transformation Backlog
    Planning Transformation
    Strategic
    Refactoring 1
    Product Backlog
    User Story E
    User Story C
    User Story D
    Tactical
    Refactoring 1.4
    Tactical
    Refactoring 2.1
    Strategic
    Refactoring 2
    Sprint Backlog
    User Story F
    User Story G

    View Slide

  78. @hschwentner
    Transformation Backlog
    Planning Transformation
    Product Backlog
    User Story E
    Tactical
    Refactoring 2.1
    Strategic
    Refactoring 2
    Sprint Backlog
    User Story F
    User Story G

    View Slide

  79. @hschwentner
    Transformation Backlog
    Planning Transformation
    Product Backlog
    User Story E
    Tactical
    Refactoring 2.1
    Strategic
    Refactoring 2
    Sprint Backlog
    User Story G
    User Story H User Story F
    User Story I

    View Slide

  80. ContractService
    signContract()
    voteContract()
    Code
    Contract
    getContractNumber()
    setSignatureDate()
    setCreditRating()
    setVotingResult()
    Risk Assessment
    ContractService
    Contract
    Monolease
    voteContract()
    getContractNumber()
    setCreditRating()
    setVotingResult()

    View Slide

  81. ContractService
    signContract()
    Code
    Contract
    getContractNumber()
    setSignatureDate()
    Risk Assessment
    ContractService
    Contract
    Monolease
    voteContract()
    getContractNumber()
    setCreditRating()
    setVotingResult()

    View Slide

  82. @hschwentner
    Tactical

    View Slide

  83. Code
    Risk Assessment
    ContractService
    voteContract()
    Contract
    getContractNumber()
    setCreditRating()
    setVotingResult()
    anemic

    View Slide

  84. View Slide

  85. @hschwentner
    Outlook

    View Slide

  86. @hschwentner
    What Else?
    Socio-technical transformation
    Technical transformation
    Tactical transformation
    Anti-Anemia refactorings

    View Slide

  87. @hschwentner
    Domain Categories
    Pipeline Domain Blackboard Domain Dialog Domain
    • Logistics
    • Insurances and banks
    • administration
    • healthcare
    • event management
    • control center
    • Software development
    • Communication software
    • Negotiations in various
    domains
    or Domain Patterns?

    View Slide

  88. @hschwentner
    Conclusion

    View Slide

  89. View Slide

  90. https://hschwentner.io
    Read on in:
    https://hschwentner.io/domain-driven-refactorings

    View Slide

  91. Lesson:
    is possible
    Monolith transformation
    (and hard)
    =>

    View Slide

  92. @hschwentner
    Mistake: Going on the journey alone
    Better:

    View Slide

  93. Photo: Henning Schwentner

    View Slide

  94. !

    View Slide

  95. @hschwentner

    View Slide

  96. Bibliography
    Foote, Brian and Joseph Yoder. “Big Ball of Mud.” PLoP ’97, Monticello, IL,
    September 1997.
    Fowler, Martin. “Strangler Fig Application.” Bliki, June 29, 2004.
    Hofer, Stefan and Henning Schwentner. Domain Storytelling: a Collaborative,
    Visual, and Agile Way to Develop Domain-Driven Software. Boston: Addison-
    Wesley, 2022.
    Lilienthal, Carola and Henning Schwentner. Domain-Driven Transformation.
    Heidelberg: dpunkt, 2023.
    Kernighan, Brian W. Software Tools in Pascal. Addison-Wesley, 1981.

    View Slide

  97. View Slide

  98. Henning Schwentner
    ⌂ https://hschwentner.io
    @hschwentner
    [email protected]

    View Slide

  99. (Software) Seam:
    A place where you can alter
    behavior in your program without
    editing in that place
    Every Seam has an
    enabling point, a place
    where you can make the
    decision to use one
    behavior or the other

    View Slide

  100. View Slide

  101. Typical Seam:
    An interface that can have
    different implementations

    View Slide