MEPX
Chapter 10 of 10All chapters

Chapter 10 of 10

When not to use it

Other ways to organise code.

Functions are often enough

A transformation with no state is a function. Wrapping it in a class with one method and no fields adds ceremony without adding structure.

  • Functional style favours immutable data and pure functions, which are simple to test.
  • Most real codebases mix both and are better for it.

Choosing

Objects suit domains full of things with identity and rules: accounts, orders, documents. Pipelines of data transformation suit functions. Match the shape of the code to the shape of the problem.