Imagine you have a method on the server side, in one of your entities Repository.
This method INSERTS or UPDATES Foo entities in the Db.
And you need to name this method.
From the naming convention point of view, can you explain the differences -if there is- between those names:
- SaveFoo(Foo foo)
- PersistFoo(Foo foo)
- CreateFoo(Foo foo)
- SaveOrUpdate(Foo foo)
Or what is the naming convention for such methods that only INSERTS or UPDATES to Db?
If you work in a team, you should first try to find out if there is a convention there, as it’s usually more important to be consistent than to find the absolute best name for something.
Using Save or Persist would work, as they don’t imply anything about the previous state.
Using Create would imply that the item doesn’t already exists, i.e. an insert.
Using SaveOrUpdate could be somewhat confusing, as Update implies that the item already exists, but Save doesn’t imply anything about the state, so they overlap.
Perhaps InsertOrUpdate would be an alternative, or CreateOrUpdate. Either would work as Insert and Create implies that the item doesn’t exist yet, and Update implies that it does exist, so they don’t overlap. They are also more precise than Save or Persist, as the names specifically say that they handle both insert and update.