I often see classes that look a little like a phone book. They contain a little bit of information about a whole lot of objects. For example, I recently ran across a class that had a method for every kind of resource the system managed. Each of those methods had the name of the resource as part of the method name. If you wanted to add a new kind of resource to the system, you needed to add a method to this class. In general, this is a code smell. That phone book class was coupled with many other classes and was hard to maintain. It causes unnecessary dependencies between classes and unnecessary coupling. There are two solutions to this problem. You can put the method into the resource class or you can build a mechanism where you can register objects with the phone book class without requiring the phone book class to explicitly have methods named after the things it manages. Either way, it's better than having lots of methods that couple your class to many others.
Download