views:

668

answers:

2

Martin Fowler suggests using a service layer as a boundary between the domain model and and "Data Loaders". However, Rockford Lhotka suggests building validation into the business object itself and this is exactly what CSLA.NET does.

The benefits of abstracting this into a service layer is obviously that your service layer can coordinate the activity/operation across multiple business objects. But what are the other advantages and disadvantages of using a service layer over directly using business objects for business logic and validation?

A: 

I am definately in the camp of Rocky Lhotka. I believe that your business objects should be very easy to "port" between applications and UI layers. Adding an additional "service layer" will most likely add a dependency with your objects and therefore make them less "portable".

If you write your business object framework correctly, your business objects should be able to handle the validation correctly between various business objects. CSLA.NET does this correctly by having parent/child relationships as well as the concept of dependent property validtion.

Jamie Wright
+2  A: 

Hello,

I'm not sure if you have figured this out.

Martin Fowler suggestion in the PEAA is the Service layer an API between the UI (or clients) and the Domain/Data layers. it will expose any functionality that can be consumed by a client.

If you look at the Domain Model (Here)

An object model of the domain that incorporates both behavior and data.

The Domain tier will contain these objects, which will have actions/validation (Behaviour) and state (Data)

These objects can be reused in other applications, this will also depend upon your design. the domain layer should not be dependent on the service layer

So considering that Domain objects have behaviour (this includes validation) and data. the Service layer is what you want your application to expose (to functionaly do). IE add a customer, or account, calcualte the Bills for the end of month.

Have a look at sharp architure's layout (http://www.sharparchitecture.net/)

This is my understanding of this meterial.

HTH

bones

dbones