1. Prefer broad, shallow hierarchies
a. Less than or equal to two additional levels = rough rule !
b. Contracts and responsibilities are difficult to maintain and explain in deep hierarchies
2. Consider making base classes not constructible (use abstract class)
a. Make it clear what the class is for
b. Provide a protected constructor for subclasses to call
3. By default, everything should be non-virtual.
a. There is the danger and power of virtual methods
i. Danger : Owner of base classes cannot control what subclasses do
ii. Power : Base class don't have to change as new subclasses are created
b. Always consider LSP
4. Use abstract members only where it is absolutely required
a. There is more chance of introducing bugs.
5. Interface vs. Base Classes
a. Its easy to add members to base classes but not to interface. You have to create a new interface version.
Saturday, January 3, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment