I have a database class with the following interface:public Database {    //returns false if p (its ID) is already available    //otherwise adds p the the list and returns true    public boolean create(Person p);    //returns false if p (its ID) was not found in the list    //replaces the available Person q (q.ID == p.ID) with p and returns true    public boolean update(Person p);    //returns false if p (its ID) was not found in the list    //marks the available Person q (q.ID == p.ID) as inactive returns true    public boolean remove(Person p);}The Person is immutable and can be identified by a unique id. I have a EditDialog which looks like this:I wanted to reuse my code and so the EditDialog is used for create a Person or update it. So this dialog is initialized either by a available Person instance (Edit-Operation) or by a new one (Create-Operation). Because I learned that there is always an evil user I wanted to avoid the following scenario:Click Create Person buttonNew Person is created in DatabaseEditDialog for new Person is displayedClick Chancel buttonPerson has to be removed (= marked inactive) from DatabaseEditDialog is disposedrepeatWhich would lead to many inactive Persons in the Database. So I decided to only create the Person in the Database, if the user clicks the Save button. Which leads to two possible scenarios for the Listener of the Save button:New Person should be created in DatabasePerson should be updaated in DatabaseSo the code of the Listener looks like the following:if(!database.create(p) {    database.update(p);}Which is not so pretty in my opinion. The Long and the short of it is, should the Database automatically update a Person if it's availabe at invokation of create(Person)?create a Person if it's not yet available at invokation of update(Person)?Or is there another solution/practice I didn't think about?
Automatically create or update object in database
java;design;programming practices