Though J2ME forces you to be close with adding classes, type-safe & convenient persistence might be something you don’t want to miss.
And as RecordStores are the primary application persistence stores, there’s some boilerplate code you can refactor out into one single common base class.
Also โ especially from a pattern standpoint โ it’s a must and increases the unterstandability and maintainability of your code.
So what’s the design assumptions and decisions?
- multiple RecordStores can be kept open at least as long as an application is active. So open them in startApp() and close them in pauseApp() and destroyApp(),
- use the ActiveRecord pattern rather than ValueBean/DAO to keep the number of classes small,
- never access RecordStores directly but shield them with ActiveRecords,
- keep track of the ActiveRecord instances and update them via RecordListeners,
- provide getBytes/setBytes instance methods to the ActiveRecords,
- maybe make ActiveRecords even RecordListener Singletons and refill the data on usage,
- maybe even use a single Hashtables subclass as ActiveRecords to even save more classes (requires very disciplined unit testing!),
- create few multi-purpose RecordFilter and RecordComparator subclasses per RecordStore,
Check back later for sample code.
Or just don’t code persistence manually but use the floggy J2ME persistence framework. Looks interesting, but I didn’t try it out yet.