views:

39

answers:

1

In terms of memory management, memory footprint and ease of developer use what would be the best practice for creating helper methods for a custom entity object.

So I have my object and I need a get, save, get history, maybe even a find method. The three options would be:

  1. Include the methods in the object themselves (get would be non-intuative that you would have to create a new object then do:

    myObject.Get(id)

  2. Include the methods as static methods of the Object Type.

    MyObject myobject = MyObject.Get(id)

  3. Create a new class of static methods, this would require the developer to possibly include two dlls for the project. Entity, EntityHelper in every reference

    MyObject myobject = ObjectHelper.Get(id)

It seems that Microsoft has chosen option 1, I use List as the example the object has the add, find and contains method.

If you choose to reply, first of all thank you, second can you describe how memory and garbage collection is handled in each case.

A: 

It really depends on what type of development paradigm you're looking at. Personally, I go for an inversion of control model, and I would have a class specifically set up for retrieving that object type from its underlying storage. So the consumer would call

MyObject myObj = MyObjectFacade.Get(id); 

Which would return an object of type MyObject. Then you could call

MyObjectFacade.Save(myObj);

That way the business entity would JUST represent the fields in question, and then you could have any number of objects responsible for saving and creating the object.

alc6379