I have a java/swing application in (hopefully good) MVC structure. Here is a overview of my model classes:
One or more worker
s may work at one working location
and one worker
may work at different working location
s (not at the same time, of course). A worker
may have different types of a date
assigned. The working location
has a list of all its worker
s. Each date
has a reference to its worker
. All model objects are mutable.
For managing purposes I implemented a Database.java
which is responsible for storing the model classes in java collection classes and at program close saving all objects into an xml file (I use java simple xml framework for this task). It has the following three lists: List<Working location>
, List<Worker>
and List<Date>
. So the procedure is:
- Load xml file on program start
- Add/edit/remove model-objects to/in/from database (working with the collections of Database.java
- Save all model-objects from the Database collections into the xml file on program exit
(If there is something bad in my mindset until now, please tell me a better way! I will really appreciate it.)
Here is the question:
What is the proper way of identifying model-objects?
I can think of two possibilities:
- Use object references
- (+) There is no extra code for handling the generation of new unique ids
- (-) "Everyone" can edit the objects (Because this is a private project "Everyone" means only me)
- Use unique IDs for every object
- (-) more code
- (+) database may return copies of the model objects to be edited and only when the controller calls the database's methods with the copyied model objects they will be updated
EDIT:
There was an important part which I forgot to mention: Multi-Threading and Multi-User
Both of them can certainly be answered with "No". The application will be some kind of one user planning software to replace the current "pen-and-paper-planning". I would say the main requirement is to avoid budgeting workers who are on holiday or not to forget to budget workers who come back from holiday the next day. Because this are the mistakes that often happen.
Also there is no need for deeper analysis of the model objects and therefore no need for complex database queries at the moment. Therefore I like the idea of using XML to create a standalone application. Or is there a good reason to blow up the code to fulfill unlikely requirements?