If the work can be done inside the signle object (and, of course, this is a relationship), then it should be placed there. I mean, if the operation is associated with a change in the state of an internal object .
Otherwise, if this task needs to use other parts of the application, such as a database, or is performed on several issues unrelated to it, I would suggest using services .
What for what. A service is basically a class that can do something. Using the Service container, you can transfer any dependencies to it so that it is very flexible and easy to use.
For example $order->queueForDelivery() . This can mean several different things:
- change the internal state, for example change
status , to queued_for_delivery - then it should be in the Order entity class $order should be placed in Queue , which is another essential class, then it should be in the Queue class, as $queue->addOrder($order)- this queue is an external service such as RabbitMQ or something else. Then you should use the service class.
source share