In my system I have several classes that are not instantiated according to some configurations values. In some less frequent cases, they are not instantiated and calling it's method should just do nothing for each of it's methods. Currently, my solution is to ask whether the class instantiated, and only if so to call it's method (by && operator). So in my code whenever someone adds some new method to those classes or using an old one, if he forgets to check if it's instance was formed it leads to a bug. I think that my current solution is not elegant, makes the code less readable and bugs prone. Any suggestions? I wish to find a solution that will be applied to every new method that will be written (or at least fail in compilation if developer didn't take care of this case), and avoid checking every time applying a method whether it's class instance instantiated. Any suggestions?
Aucun commentaire:
Enregistrer un commentaire