Best practice for creating a helper method for a business object

In terms of memory management, memory size, and simplicity, developers use best practices to create helper methods for a custom entity object.

So, I have my object, and I need to get, save, get the history, and maybe the find method. Three options:

  • Include methods in the object itself (get will be unintuitive that you will need to create a new object:

    myObject.Get (ID)

  • Include methods as static methods of an object type.

    MyObject myobject = MyObject.Get (id)

  • Create a new class of static methods, this will require that the developer can include two DLLs for the project. Entity, EntityHelper in each link

    MyObject myobject = ObjectHelper.Get (id)

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

If you decide to answer, first of all, thanks, and secondly, you can describe how memory is processed and garbage collection in each case.

+3
source share
1 answer

It really depends on what type of development paradigm you are looking at. Personally, I use the inverse of the control model, and I will have a class specifically configured to retrieve this type of object from its main repository. So the consumer would call

MyObject myObj = MyObjectFacade.Get(id); 

To return an object of type MyObject. Then you can call

MyObjectFacade.Save(myObj);

, - JUST , , , .

+1

Source: https://habr.com/ru/post/1746868/


All Articles