This is the Service abstract class (I don't want to force the user to redefine terminate and initialize):
package schedule;
public abstract class Service {
public abstract String getReferer ();
public static void terminate () {
}
public static void initialize() {
}
}
I'm making a Scheduler to operate treatment on a whole set of Services it has stored.
Scheduler is a Service, and it is an observer, and every Service is a Singleton.
Without talking about Singletons (I have already seen StackOverFlow mad over these, but I need a pool of classes with single controlled access) is it a bad idea to try to store types ? In that way, i could make something like
Set<Class<? extends Service>> servicePool; // defined in the ctor as a TreeSet
public static void initialize () {
if (instance == null)
throw new CustomException("Ill-initialised Scheduler");
for (<? extends Service> S : instance.servicePool)
S.initialize(); // static function called on S as a class.
}
Would that be a bad thing ? and Why ? Else, How to do it ? Maybe I shouldn't put initialize (and terminate) static in Scheduler, but it would mean to either stop it from being a Service (which is wrong, semantically) or to make initialize instance-dependant, which would lose all the interest of this Service thing.
Moreover, I will likely run lots of dead code (for the Services which didn't (for instance) redefined terminate (). Is there a way to test if (function is redefeined) then run function
?
Aucun commentaire:
Enregistrer un commentaire