schmoopy schmoopy - 1 year ago 74
C# Question

Factory Class - Should i populate my object with data here?

im creating a Factory class that will contruct and return an object. I normally would do all of the data stuff at the Data Access Layer, but i dont think i could reach my objective and still do so. What i want to do is use a SQLDataReader to quickly read the data information and populate the object to be returned from the factory. Is this a stupid idea? Is there a better approach? I would prefer not to just return a DataSet from the DAL if possible, or is it a question of performance vs. maintainability?

Answer Source

In most cases this is a good idea as this way provides two major benefits:

  1. This way you can seperate the data access and business logic, which means if you change database design the upper layer algorithms do not need to be changed.

  2. From OO stand point, you are converting some pure data into objects and may also added behavior to the objects, which makes the code easier to maintain and reuseable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download