mercredi 1 mai 2019

Best practice regarding encapsulation and single responsibity design

I've been developing a many years and a common problem I face is how best to separate out the service layer. I've been using the repository pattern mainly, but I still struggle with this common scenario.

Customer service that returns a single customer. Invoice service that returns a list of invoices by customer.

The consumer of the service sometimes wants just a Customer other times they want the customer and the invoices which is fine to leave as two calls.

But a new requirement may be they want the Customer, but also want the total number of invoices the respective customer has.

I do not want to corrupt the GetCustomer method and do not want to return a list of invoices and have them do a count (this would work). Is there a best practice without getting into create a lot of one of methods while still keeping performance and round trips in mind? I see a lot of designs where there will get GetCustomer, GetCustomerDeepLoad, etc.

thanks.

Aucun commentaire:

Enregistrer un commentaire