vendredi 1 septembre 2017

Best way to implement class selector

Before I would use Enums to select a tool I want to use (enum tool {brush, eraser, drag}). But to make everything more efficient instead of using Enum I now create a class for each tool that derrives trom base class "ToolType". Then I use reflection to find all classes that inherit from ToolType and place them in a static array. And now I'm using this method for most of things in my project, it's easy to add/remove things, no need to edit enum array every time you add a new class. It feels like a best solution to modular project, but I'm yet to find any examples of this, so I'm not sure if I'm doing it the right way. What should I be looking for?

P.S.:

I'm just afraid that at some point somebody will look at my code and say "This thing you do is suboptimal, there is already well developed method, this is how you should do it. Rewrite everything now."





Aucun commentaire:

Enregistrer un commentaire