Implement a Save method for my object

后端 未结 3 843
时光取名叫无心
时光取名叫无心 2021-01-16 16:11

I\'m trying to improve my application\'s design, So instead of calling the DataAccess layer from the presentation layer. I\'ll try to implement a save method from my object

3条回答
  •  一整个雨季
    2021-01-16 16:48

    if you follow this pattern you will have the saving logic inside the object definition itself, so when you call from PL:

    obj.SaveObject();
    

    this will happen in the Object itself:

    public void SaveObject()
    {
      DAL.SaveObject(this);
    }
    

    and your DAL stays the same as you shown above.

    it's a matter of design, I would not put the logic of saving inside the object but I would have a BusinessManager or an ObjectMapper to read from DAL and save to DAL.

    in general is a good practice to have read or load and Save in the same place, BusinessObject or BusinessManager, but together so you find them easily and update both in a breeze if you add or change a field.

提交回复
热议问题