NDR01 Interactor postfix for classes that handle business logic
Context
There are several options for naming a class that handles business logic. We need to choose a naming convention for this.
Option
Service
The term “Service” is commonly used in various software design patterns and architectures to denote a component that encapsulates business logic or provides a specific functionality.
Service-Oriented-Architecture
Controller
The concept of a “controller” existed even before MVC, though not as a formal pattern. It was used in various domains, particularly in systems and embedded programming, where controllers were components that managed the flow of control in a system.
Due to the popularity of the MVC design pattern, developers usually think about something else when we are talking about controllers. Therefor it is less suitable as a name for business logic components.
Interactor
The term “Interactor” originates from the Clean Architecture and Hexagonal Architecture (also known as Ports and Adapters Architecture) paradigms, both of which were popularized by software architect Robert C. Martin, often known as “Uncle Bob.”
UseCase
The concept of “Use Case” has its roots in object-oriented programming and software engineering, but its formalization and widespread adoption came from the field of requirements analysis and design, particularly influenced by the Unified Modeling Language (UML).
Handler
The use of “Handler” as a postfix for classes that manage business logic comes from a variety of design patterns and software architecture principles. It is commonly used to denote classes responsible for processing specific requests, commands, or events.
Command Pattern, CQRS
Reason
“Service” has become an overused or ambiguous term in software development. You can encapsulate business logic in a service, or provide specific functionality through a service. But it is also used for classes that call external APIs. And many other software related use cases, such as: web-, windows-, application-, email-, and hosting service.
Due to the popularity of the MVC design pattern, developers usually think about something else when we are talking about controllers. Therefor it is less suitable as a name for business logic components.
Handler has strong connections with the Command Pattern and Event handling. Should the business logic care that it is handled as part of an event or command pattern?
Interactor, UseCase, and
Handler are acceptable names, choosing which one to use can
be done by personal preference.
My personal preference is Interactor
Decision
We will use Interactor as postfix for classes that handle business logic
Consequences
- Our business logic classes are postfixed with Interactor.
- For example:
OrderInteractor
- For example:
References
- Hexagonal architecture (software) - Wikipedia
- MVC: Model-View-Controller - Wikipedia
- SOA: Service-Oriented Architecture - Wikipedia
- OOP: Object-Oriented Programming - Wikipedia
- UML: Unified Modeling Language - Wikipedia
- Command pattern - Wikipedia
- Command Query Responsibility Segregation - Wikipedia