One software technique I often see is a method that returns an array of classes to use for some purpose. For example, you might have a method that returns an array of the number classes like Integer, Float and Fraction. The problem with this technique is that the method needs to be modified whenever any new class needs to be added to the list. The technique also can't deal with classes that might be dynamically loaded or packaged out of a runtime image. The better way to handle this problem is to set up a registry. When they are loaded, the classes can add themselves into the registry. If they are unloaded, they can remove themselves from the registry. As with anything, there are times when a simple approach is the best and a method that lists a number of classes is fine. Before you make this decision, however, consider whether this list will ever change and what the consequences will be if it does.
Download