Home > database >  Design update functions and their naming convention
Design update functions and their naming convention

Time:10-19

I am writing updaters for my component-store.

The situation is as follows:

  1. I have an Array Of models named processingStatuses.
  2. Sometimes t I have to update all of them.
  3. Sometimes I just want to update one of them.

I am wondering which design is better.

  1. Separate this into 2 functions.
readonly updateOneProcessingStatus = this.updater(...);
readonly updateProcessingStatuses = this.updater(...);
  1. Always pass the whole array to the updater. When I want to update one, I get the array from the old state, modify it and then pass it to the updateProcessingStatuses().
readonly updateProcessingStatuses = this.updater(...);

And I also want to know if my naming is acceptable or not. (e.g. plural)

Thanks!

CodePudding user response:

In my view, it is better to create two functions update() and updateRange(). By doing this your API will be cleaner and when new developer will try to update, then she/he will have clear understanding what method should be used.

In addition, it can be seen that this approach is used in Entity Framework. UpdateRange() and just simple Update() method

  • Related