concept domain logic in category system administration

appears as: domain logic, domain logic
Functional and Reactive Domain Modeling

This is an excerpt from Manning's book Functional and Reactive Domain Modeling.

Table 1.3. Why mixing domain logic and side effects is bad

Mixing side effects and domain logic

Why it’s bad

Entanglement of domain logic and side effects. Violates separation of concerns. Domain logic and side effects are orthogonal to each other—entanglement violates a basic software engineering principle.
Difficult to unit test. If domain logic is entangled with side effects, unit testing becomes difficult. You need to resort to mocking that leads to other complications in your source code.
Difficult to reason about the domain logic. You can’t reason about the domain logic that’s entangled with the side effect.
Side effects don’t compose and hinder modularity of your code. Your entangled code remains an island that can’t be composed with other functions.

You need to refactor to avoid this entanglement, and you need to ensure that side effects are decoupled from the domain logic. The next example splits the two operations into separate functions and makes sure the domain logic remains a pure function that you can unit test in isolation. That’s exactly what listing 1.10 does. It introduces a new function that does the verification through interaction with the external system. After it completes, it passes on a successful Customer instance to the openCheckingAccount function that does the pure logic of opening the account.

  • Domain logic is now more explicit. A separate data type encoding the account type makes the domain model more expressive.