Last week I got some emails from colleagues regarding “C# Coding Standards”. Lance Hunt’s “C# Coding Standards for .NET” caught my eye and especially the part about Object Model Design.
- Always prefer delegation over inheritance.
- Avoid “Premature Generalization”. Create abstractions only when the intent is understood.
- Do the simplest thing that works, then refactor as time permits.
- Always make object-behavior transparent to API consumers.
- Always separate presentation layer from business logic.
- Always prefer interfaces over abstract classes.
- Try to append the design-pattern name to class names where appropriate.
- Make members virtual if they are designed and tested for extensibility.Consider using the sealed keyword to break the inheritance chain.
- Refactor! Refactor! Refactor!