Decoupled Functions: Behaviour lives in standalone functions that take data in and return data out, not as methods attached to that data. Decoupled functions are standalone functions that take data in and return data out, instead of being methods tied to a particular object. calculateVat($amount, $rate) works with any amount, from any source.
Frequently asked questions about Decoupled Functions
How is Decoupled Functions used in practice?
Because they do not depend on hidden state, they are easy to test. You pass input and check output, with no setup of objects or mocks. They are also easy to reuse in places the original author did not foresee.
What should you keep in mind with Decoupled Functions?
This style comes from functional programming, but it fits well in any codebase. A good candidate is logic that does not really belong to one class, such as price calculations, date rules or formatting. Keeping it in small, pure functions avoids the god classes that accumulate every helper in the project.
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.