There is a good example taken here:
CRUD x Business logic interface. Suppose that you are working with Invoices. Each invoice consists of an InvoiceHeader and one or more InvoiceLine. If you use a CRUD interface for invoice you will first call CreateInvoiceHeader operation to create InvoiceHeader and then several AddInvoiceLine operations to add all InvoiceLines - that is low level CRUD approach. But if you implement business logic on the service side you will call single CreateInvoice and pass a complex object graph (header with all lines) to the service to create and add what is needed.
Why a perfectly legal method composition
var Invoice =
Service.CreateInvoice(
Service.CreateInvoiceHeader(...),
{
Service.CreateInvoiceLine(...),
Service.CreateInvoiceLine(...)
}
)
- is absolutely awful from performance point of view when used in SOA?
- can't be translated automatically into a single Service call?
Why must one instead create a complex object graph and send it to the service method
var InvoiceDTO = new InvoiceDTO(
new InvoiceHeaderDTO(...),
{
new InvoiceLineDTO(...),
new InvoiceLineDTO(...)
}
)
var Invoice = Service.Create(InvoiceDTO)
and the Service must traverse the whole graph and call just the same Service methods to assemble the resulting Invoice?
Is there any way to use method composition to create complex results without using complex object graphs as data transport?