Blog de notas sobre Software, Ingeniería y Tecnología

How to decouple domain entities: The author explains that the first step is to replace the object references between the entities with primitive types that represent the foreign keys in the database. For example, instead of having a Customer object in an Order object, you would have a customerId field of type Long. The second step is to assign the responsibility of data based on who modifies it. For example, if the Order module changes the status of an order, then the Order entity should own the status field. The third step is to define an interface for each module and use DTOs (Data Transfer Objects) to communicate with other modules. For example, if the Customer module needs to access some data from the Order module, it should use the OrderService interface and the OrderDTO class.
Order module depends on the Customer module and vice versa, you could extract a Payment module that both modules depend on, or use an event bus to publish and subscribe to events between the modules, or invert the dependencies by using abstract interfaces, or create a CustomerOrderService that acts as a facade for both modules, or simply combine the Order and Customer modules into one.