The difference between a class and an instance of a class
There is a discussion in the TDD Yahoo Email group about class vs. instance of a class with regard to its design. Spesifically, the issue is the difference between:
Employee emp = Employee.Find("John");
Vs.
Employee emp = employeeFinder.Find("John");
The discussion revolves around managing the responsabilities of a class. For myself, I stand firmly on the first sentence, the responsability for locating an object of the class should be in the hand of the class. After all, it's an object as well (not a very dynamic one in C based language, but it does exists), why should we let it avoid any responsabilities? I don't really see a point with creating a finder object that is strongly tied to its findee type.
This is one of the reasons that I like Active Record so much, I guess.
That said, I would make an exception for a generic Finder / Repository object, like this one:
Employee emp = Repository<Employee>.Find("John");
Since this type isn't coupled to the Employee type. If fact, I make an extensive use of this in a one of my projects (where the data is persisted via Active Record, but I needed to insert more checks along the way).
Comments
Comment preview