A class should have one, and only one, reason to change.
-
Large Class
- You can't easily describe what the class does in one sentence.
- You can't tell what the class does without scrolling.
- The class needs to change for more than one reason.
- The class has more than seven methods.
- The class has a total flog score of 50.
-
Divergent Change
- You can't easily describe what the class does in one sentence.
- The class is changed more frequently than other classes in the application.
- Different changes to the class aren't related to each other
-
Duplicated Code
- You find yourself copying and pasting code from one place to another.
- Shotgun surgery occurs when changes to your application require the same small edits in multiple places
You should be able to extend a classes behavior, without modifying it.
-
Large Class
- You can't easily describe what the class does in one sentence.
- You can't tell what the class does without scrolling.
- The class needs to change for more than one reason.
- The class has more than seven methods.
- The class has a total flog score of 50.
-
Divergent Change
- You can't easily describe what the class does in one sentence.
- The class is changed more frequently than other classes in the application.
- Different changes to the class aren't related to each other
Derived classes must be substitutable for their base classes.
- Explicit checking for type
- is_a?
- kind_of?
- case
- respond_to?
Make fine grained interfaces that are client specific.
- ActiveRecord methods outside of ActiveRecord models.
Depend on abstractions (module or duck type), not on concretions (class).
- depend on things that change less often than you do
- Explicit checking for type
- is_a?
- kind_of?
- case
- respond_to?