How to name 2 parameters for old and new entity state in an update/creation method?

34 Views Asked by At

Our (Java) project deals with multiple entities stored in a relational database. For example, we deal with persons. We have service methods (on singletons) which allow creation or modification of these entities. These accept at least 2 parameters:

  1. one for the state of the entity as requested in the HTTP POST being processed,
  2. and the other for its state before the POST, if it existed, or null (undefined) if it doesn't exist yet

For example, if we had an updatePerson method, its prototype could be:

public void updatePerson(Person person, Person personDB) {
   ...
}

When the user fills a form and clicks Save, person corresponds to the object described by the form, while personDB is null if it's a creation, or what was in the database before the user clicked. In other words, our parameter naming convention is entity vs entityDB, which I find understandable, but not great.

I would prefer that both names be more specific, for example personModified vs personExisting. Yet, I am not so keen on personModified since I don't want to give the reader the impression that the code is necessarily modifying (rather than creating). Are there standard naming conventions for this pattern, whether in Java or generic?

By the way, our project is actually in French (in case someone has a solution which doesn't work in English).

1

There are 1 best solutions below

0
HostMan On

I see two ways:

  1. I am prefer existPerson\person and modifiedPerson
  2. But you can pass into your method only personId and person (modified) dto. next, retrieve storedPerson from DB by Id and mapp it, if exist. in the body of method, you can use storedPerson / entity names.