So I have been reading the blog at http://www.codinghorror.com/ and came across this great principle - SRP. SRP says that each class should have only one reason to change. The example cited was of an employee class containing 3 funtions - salary, save, hours. The problem with this is if the human resources department changes the way salaries are computed, the class is changed, and again if either of the remaining are changed at some other level. The change in any one of these could end up breaking the whole class. So each should be it's own class.
This however breaks the idea that the Employee class should contain all those things relevant to an employee. I guess the salary class could be derived from an non-instantiated employee class? Or maybe the employee class should only worry about variables relevant to the employee and one action such as save. Hmmm, I think I have broken this rule many times.
No comments:
Post a Comment