R – Validation and in Service Layer or Business Objects

business-objectscsladesign-patterns

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?

Best Answer

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

Related Topic