Is there a way to setup the following construct in JAVA:
- having a common interface or base class
- having a static public field declared by the common interface
- each model implementing the common interface should have its own static field (not one shared instance for all models)
Detailed explanation: I'm working with ORMLite and I need to refresh the ForeignCollections of my models after deserialization. For doing this I need to have a reference to my DAO from the models, which I don't want to.
So, I came up with the following concept:
keep a static field in each of the models of the following Interface:
public interface SerializableObserver { void onAfterDeserialization(Object object); }in my implementation of
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundExceptionafter reading in all ivars i'am calling theonAfterDeserialization-Method of the static field i'am holding in the model.- In the Dao, I'm setting the static field of the model. So when the deserialization is finished, a method in my Dao is called. Where i can finally refresh the ForeignCollection so it's still valid after deserialization.
So what I'm looking for is some sort of way to make this whole approach a bit more generic so, I don't have to implement this behavior for all of my 20 Models. And finally, this is going to be an Android-App. so no fancy Java-8 things.