Reputation: 1265
There is a Service to work with a Customer
entity.
Service already implements a GetCustomer
method which returns a CustomerDTO
.
Service must implement methods to change Customer's Phone
, Address
, SalesManager
and Discount
. Customer is allowed to change only Phone
and Address
, Sales Director is allowed to change only Customer's SalesManager
, while Sales Manager is allowed to change only Customer's Discount
.
ChangeCustomer
?
CustomerDTO
which I used as a return type in GetCustomer
method, e.g. ChangeCustomer(CustomerDTO)
?CustomerChangeDTO
, e.g. ChangeCustomer(CustomerChangeDTO)
?ChangeCustomerPhone
, ChangeCustomerAddress
, ChangeCustomerManager
and ChangeCustomerDiscount
?
CustomerDTO
in each of these service methods, e.g. ChangeCustomerName(CustomerDTO)
, ...?ChangeCustomerName(CustomerNameChangeDTO)
, ...?It seems that a single DTO class makes service much easier to use on client, because all client has to do is to request CustomerDTO
, change some of it's properties and send back. Service is to process all changes in CustomerDTO
and apply business logic to real Customer
entity and maybe other entities.
Are there any other pros / cons for each variant?
Upvotes: 3
Views: 1299
Reputation: 14904
Your WCF service is in the application layer, so it should have a separate method for every use case. You clearly have 3 use cases here:
Phone
and Address
SalesManager
Discount
So your service should expose 3 methods. Each of these methods will not only have to update Customer
entity, it will have to check permissions first. If you try to implement it in 1 method, you will end up with a lot of if
s and unclear behavior. For example what to do if a Sales Manager tries to change Discount
and Phone
? Ignore the Phone
? Throw an exception?
Each method should use a different DTO, containing only properties necessary for the method. (Btw, you can change 'DTO' to 'Command' in the class names - for example ChangeCustomerDiscountCommand
. Looks nicer than 'DTO').
If you use a single DTO, it will be confusing for the client (Why are there other properties in the class? What will happen if I leave them empty? What will happen if I change them? etc.)
Upvotes: 3