I have a separate DataManger class that handles reading and writing records to\from the data file. I'm grappling with the idea of whether I should include the deleted flag in the information returned from this class and if so, where in the array I should put it.
DataManager
I have two methods in my DataManager class:
1) List<
String[]> readRecords(final String path)
2) writeRecords(final String path, final List<String[]> records)
So my readRecords method will return a list of String[] objects where each such object is a record. I'm thinking of adding the deleted flag as the last element in this array. The reason being the search criteria from my DB interface is:
So it wouldn't make sense to have the deleted flag at any position other than the last position in the array. That way code that is using the find() method can set values in the String[] for the criteria and I can compare that directly to the record String[] which will be one element longer.
My record String[] will contain EIGHT elements : {Name, Location, Size, Smoking, Data, Rate, Owner, Deleted}My search criteria String[] can contain up to SEVEN elements : {Name, Location, Size, Smoking, Data, Rate, Owner}
So record[0] and criteria[0] will both be referring to the Name field, record[1] and criteria[1] will both be referring to the Location field, and so on.
I think my DataManager class does have to return information about the deleted flag and then receive information about the deleted flag when writing records back to the file. So the question is just where do I store this information in the String[] objects that the DataManager class uses.
Data Class
My Data class will be receiving a list of String[] objects from the DataManager class. The Data class will store these in a Map<Integer, String[]> cache - where the Integer is the record number and the String[] is the record object received from the DataManager.
Now, my strategy for dealing with deleted records is to set to set String[] value to be null. So I never actually have String[] objects where the deleted flag is set to true.
So really is there any point in me storing the deleted flag in my the String[] objects that I store in my cache? As the cache will only contain String[] objects for records that are not deleted, for records that are deleted the record number will simply map to null.
At the moment all my methods in my Data class which implement the DB interface from Oracle expect an EIGHT element String[] object. I could change this so that the deleted flag information is not visible outside of the Data class. What do people think?
Business Class
Now, when it comes to my business class, I convert the String[] record object in to a Value Object. So I am wondering should I include the information about the deleted flag in this Value Object?
On one level it doesn't make sense to me to add this information to the Value Object. It would need to then have a isDeleted() method. But by the mere fact I'm returning this record to the caller of the business method, it means that the record is not deleted!
So say I don't include the deleted flag information in my Value Object. What happens then when my client updates the record?
* My Business class receives back a Value object that does not contain any information about the deleted flag.
* My Business class then needs to convert the Value object back to a String[] in order to pass in on to my Data class
* But my Data class is expecting information about the deleted flag i.e. it is expecting an EIGHT element array {Name, Location, Size, Smoking, Data, Rate, Owner,
Deleted}
This means that my Business class would need to add in the deleted flag information before passing the String[] object on to the Data class. This doesn't seem that nice a solution. So I am wondering what other people did?