Sunday 3 October 2010

Persistence Domain Objects and Some Good Practices

In this post I’ll talk about Business layer, PDO and a few tips that will help you to have less complexity into Business layer and have one Persistence layer that will delivery data's ready to use for the Business layer.

Today most of Business Domain follow roughly this pattern:

actual_BD_chart

Where the Persistence layer is just for DAO, that is nothing wrong with it, but it doesn’t delivery data’s ready to use for the business, and because of this, it gives you one swelled Business layer, where does more than just business, especially with data's that come from Client side and Persistence layer, that’s needed convert then from entities to BO’s and then to TO’s  (or the old DTO’s). This’ telling me that the Business layer is doing more than just business is doing something else than business, where it should only take care of how data’s should be manipulated  and returning the result. Business layer shouldn't know about Persistence, should just make one call like getCustomerBO(); and work with it, not like is today, where’s needed populate all entity's then ‘filter’ the data that is needed to create those BO’s, then work with data’s and then populate those TO’s to return the result to the Client side.

One good idea that’s for sure will make your Business layer more thin, easy to maintain and performing just business tasks. Is model your application with real objects and don’t care about the Persistence layer at beginning. Real Objects means cohesive classes with encapsulated state, related behaviour and inheritance. Putting just business logic into the domain business objects, using inheritance where appropriate.

To resolve this we have an alternative that is move the convertor and BO’s to the persistence layer, and then your Business Domain will looks like this chart :

ideal_BD_chart

Following this your persistence layer will delivery BO’s ready to use for the Business layer.

In the next post I’ll go post here one very small example of this implementation.

No comments:

Post a Comment