Do More With Less

DoMoreWithLess in an OO context means the following:

  1. All attributes should be private. All methods should be public or protected.
  2. If a class has more than 3 attributes, consider reducing the number of attributes by creating more classes (grouping few attributes) and adding relations among those classes.
  3. If a class has more than 10 methods, consider reducing the number of methods by moving them up in the hierarchy.
  4. When the methods can't be moved up, consider creating an intermediate class (in the inheritance relation) to hold some attributes and methods. That intermediate class should have a meaningful name so that it could be inherited by other classes.
  5. Similar methods should have similar names.
  6. When two or more classes have the same methods, create a class than has those method and make the other inherit from the new class. If inheritance is not an option, use delegation.
  7. Make each class have one and only one responsibility. If a class has two responsibilities, divide it.
  8. Each method should have no more than 10 */ non-comment /* lines. Else consider creating new methods that group some lines. One liners are okay.

This will proliferate the number of classes. I think this is a minor problem if all classes are organized in a single thin and deep tree. By knowing the first 10% of the levels of the tree, you can manage the complexity of the system.

How do you know if your ClassModel? is OO? Only if your ClassDiagram is good.

-- GuillermoSchwarz


This seems to be a direct contravention of DoTheSimplestThingThatCouldPossiblyWork.


EditText of this page (last edited November 26, 2014) or FindPage with title or text search