Originally posted by Joakim Eriksson:
In the specs it says that you should write a class (Data.java) that implements a certain interface (DBMain.java).
I'm ok with that.
I interpret it like this:
They should be able to take my Data.java class and run it through their test programs that uses a DBMain interface.
Esentially this has some implications:
1. The database must have an "open" method to open it
2. The database must have a "close" method to close it
3. As there is no method available to acquire an instance, it
must be possible to "new" this object.
4. By the specs it must be thread-safe and keep track of who (which client)is holding a lock. I can see no easy way of doing this with multiple instances of this class. Essentially Data should be used as a singelton. However, it is difficult to enforce this pattern strictly because of 3. above.
Ok this is fine and can be done...
Essentially I ended up writing several extra public methods in the Data class, then I started thinking. Hmm, maybe it should work the other way around also. Ie, if the DBMain is supposed to be using "protected variations" I should also be able to pick any implementation of Data.java that implements the specs to the letter and plug it into my app.
And away all the extra public methods went...
1. No other public methods outside DBMain and Object
2. The database must open itself before reading/writing records
3. The database must close itself before it is gc
This can also be done, but because 1, it is very difficult to perform
efficient searching without resorting to storing all data in memory or using an intermediary file.
Hmm, anyone else thinking along these lines?
Most ppl just argue that it is fine to extend the Data class or have another class directly access the database, but is it really?
What if a RDBMS was implemented on the other side of this interface by someone else, and they insisted on using the new database with our app. It would be very sad if that meant rewriting our app, just because some custom public methods in the data layer, wouldn't it?