If you end up with an excessively "deep" hierarchy (a long list of derived classes until you get to leaf classes) or "broad" hierarchy (many, many classes derived shallowly from a single parent class).If you find you need several "friend" classes or functions, that's usually a good smell of bad SRP - because the required functionality is not actually exposed publically by your class.Perhaps a little more technical than other smells: Finding that you are making changes to the same class for unrelated bug-fixes again and again is another indication that the class is doing too much.making a change to one area in a class causes bugs in unrelated areas of the same class. Another code smell from the refactoring book would be HUGE classes.If you're having trouble getting all the responsibilities of that object on a CRC card, it's probably doing too much. If you employ a CRC card, it's a nice subtle guideline.Why would you want a single object to do all these? ( it's okay if a class takes on multiple responsibilities as long as they are all related and coherent.) However you wouldn't ask the same person to do your manage files, compute salaries, issue paychecks, and verify financial records. If the object were a person, who would I ask to do this? Assign that responsibility to the corresponding class. a service that the object provides for its clients.Ī nice way to stay on the road. to avoid class explosion.Ī single responsibility does not translate to single method classes. Well, this principle is to be used with some salt.
0 Comments
Leave a Reply. |