tonytvo / introduce-indirection-layer

practice introduce indirection layer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduce the indirection layer

  • when refactoring, we often end up in situation where single change causing cascading effects of changes and we retreat in our corner and cry, and recently, I have learned a good trick from J.B. Rainberger to introduce indirection layer to help us making small steps incrementally
  • X minutes do
    • It seems like OrderLines is a good home (domain concept) for Order.lines field, once you extract Order.lines into OrderLines, we could see a whole bunch of behavior should belong into OrderLines as well
    • Setup
    • checkout https://github.com/tonytvo/introduce-indirection-layer
    • run tests, see them pass
    • extract lines logic in class Order into methods
      • Extract a method isEmpty() to check if the lines is empty
        • extract isEmpty method
        • introduce parameter lines
          • introduce lines parameter
      • Extract a method asList() to return the list of OrderLine
        • extract asList method
        • introduce parameter lines
      • Extract a method incrementItemQuantity(ItemAdded)
        • extract incrementItemCount
        • introduce parameter lines
    • move lines into parameter object OrderLines
      • introduce lines into parameter objects for asList
        • introduce parameter object OrderLines
        • move asList method into OrderLines
          • move asList method to OrderLines
      • introduce lines into existing parameter objects for isEmpty
        • introduce existing parameter object OrderLines
        • move method into OrderLines
      • introduce lines into existing parameter objects for incrementItemQuantity(ItemAdded)
        • move method into OrderLines
      • introduce orderLines field for new OrderLines(lines)
        • introduce orderLines field
      • inline lines field
        • inline lines field

References

About

practice introduce indirection layer

License:MIT License


Languages

Language:Java 100.0%