Chapter 3: Replacing in-place mutation with data transformation

In this chapter

  • 3.1 Mutable updates versus immutable transformations
  • 3.2 Two design styles
    • Style A: behavior inside the record
    • Style B: behavior in external functions or services
  • 3.3 Comparing the styles
    • Default recommendation: start with style A
  • 3.4 Adding business-rule validation
    • Throwing exceptions: simple and direct
    • Returning a result type: explicit failure handling
  • 3.5 Transformation pipelines: connecting steps
    • Verifying each step in tests
  • 3.6 Keeping transformations pure
  • 3.7 Cancellation: separating transformation and external coordination
  • 3.8 Common questions
    • “Will creating a new object each time be slow?”
    • “Should I move every method into OrderWorkflow?”
  • 3.9 Chapter review

This chapter is not available in the free preview. Purchase the book to read the complete edition now.

Buy this book