dragonwell
Programmer
I have been using an O/R Mapper for persistence. The mapper basically has one utility class with static methods such as "GetObject(type)" and "PersistChanges(object)"
This follows the broker/manager paradigm, in that objects themselves are not responsible for persistence behaviors (CRUD), but the role is handled by a manager class, or "broker". I have determined this to be the most correct way to persist business objects, which is of course open for debate. My issue is with transactional saves - objects don't know if they are participating in the context of a transaction and should not be doing CRUD without knowing if their parent/child objects are involved.
For simple applications this works fine. In fact it simplifies the layering needed to the point where a Data Access LAyer (DAL) is not really even needed - I just use the broker instance right in my GUI code do crud business objects.
Now, in a more complex application I would like to hide the O/R mapper from the GUI layer, so that it is insulated from changes to the mapper or all out replacement. I am trying to eliminate, or at least substantially reduce, the tie-in to a particular persistence mechanism.
The way I have done this is to create a "DataManager" class which consists of many static methods, specific to the current application, i.e. - GetCustomer(cusID), SaveCustomer(), etc. These static methods are only a few lines each as they are using an internal instance of my O/R mapper to do the dirty work.
Before I know it though, this manager class keeps growing and growing... And it seems that I am creating more and more specialized methods. So I am now questioning this design. Is this what is known as "amenic data layer"?
I have thought about putting the CRUD behaviors into the business objects themselves, altough that breaks the rule of responsibility I am assuming, and plus the O/R Mapper-specific code in now scattered throught the assembly, increasing the tie-in factor.
So, what I have is working, but it seems like it is maybe not so correct.
Any comments welcome....
Greetings,
Dragonwell
This follows the broker/manager paradigm, in that objects themselves are not responsible for persistence behaviors (CRUD), but the role is handled by a manager class, or "broker". I have determined this to be the most correct way to persist business objects, which is of course open for debate. My issue is with transactional saves - objects don't know if they are participating in the context of a transaction and should not be doing CRUD without knowing if their parent/child objects are involved.
For simple applications this works fine. In fact it simplifies the layering needed to the point where a Data Access LAyer (DAL) is not really even needed - I just use the broker instance right in my GUI code do crud business objects.
Now, in a more complex application I would like to hide the O/R mapper from the GUI layer, so that it is insulated from changes to the mapper or all out replacement. I am trying to eliminate, or at least substantially reduce, the tie-in to a particular persistence mechanism.
The way I have done this is to create a "DataManager" class which consists of many static methods, specific to the current application, i.e. - GetCustomer(cusID), SaveCustomer(), etc. These static methods are only a few lines each as they are using an internal instance of my O/R mapper to do the dirty work.
Before I know it though, this manager class keeps growing and growing... And it seems that I am creating more and more specialized methods. So I am now questioning this design. Is this what is known as "amenic data layer"?
I have thought about putting the CRUD behaviors into the business objects themselves, altough that breaks the rule of responsibility I am assuming, and plus the O/R Mapper-specific code in now scattered throught the assembly, increasing the tie-in factor.
So, what I have is working, but it seems like it is maybe not so correct.
Any comments welcome....
Greetings,
Dragonwell