I have a load procedure that needs loaded objects to be initialized in a certain order, depending on the classes they belong to. Some classes hold references to other classes and depend on those other classes having been initialized first.
Right now, I define the order with a static number field in each class. The programmer is responsible of coming up with the number value. I can then sort objects by this number and initialize them in the correct order.
Is there a better way to do this? I would like each class to explicitly say which other classes it depends on (most often because it contains references to those classes), and then derive the order from that.
Aucun commentaire:
Enregistrer un commentaire