I am designing a service layer for a web application where there are overlapping services. While there are several ways to solve such problems, I would like to hear design patterns recommended by the experts in such scenarios.
I am designing a taxi app for some practice. I have two main entities here car and a driver. So, I have two separate controllers lets call them DriverController and CarController and two interfaces in the service layer lets Call CarService and DriverService and there default impls which connect to DAO layer. All of these together are good to facilitate basic CREATE/DELETE/UPDATE/MODIFY on Car and Driver entity.
No, let's say I want my application to return the list of cars owned by a particular driver
For example: {"drivername":"alex","cars":[{"carname":....etc....}]}
I would design an endpoint like GET /drivers/{drivername}/cars
which would trigger the driver controller.
Now, in the service layer, I am confused where should I write a business logic for this task. Should I add another method to the Driver Interface or should I have another interface extending this? Should I add another method like getCarsForDriver in the DefaultDriverServiceImpl or should I extend this DefaultDriverServiceImpl and add a method to it?
Here there is a one-to-many relationship between a driver and a car. Are there any design patterns/approaches to address such relationships?
Aucun commentaire:
Enregistrer un commentaire