This is the entry page of The Golden Design Rules
- No public method shall return null, this applies also to protected methods of non-final classes
- Never pass this as an argument
- Getters and Setters are evil
- A public method shall be declared by an interface (sometimes an abstract class is sufficient and more convenient)
- No switch / if-else if on class invariants (this includes instanceof)
- A class shall be either (conceptually)final or abstract
- No method declares a foreign exception (I am OK with some checked exceptions from the java* packages)
- An object that can be passed back to the API shall be immutable or a Builder
- Prefer delegation over inheritance (this makes 6. reasonable)
- The class skeleton shall fit on a single page, as do all methods (including the private methods that are used by a single method only)
- The number of ctors shall be much smaller than the number of instance methods
- All statics are in enums
Something general on this list: It is not an imperative list of things to use or to avoid. It is - as I said - a benchmark. Not even a perfect design/programm will ever score 100% over all checkpoints of a (good?) benchmark. But if you do benchmarking not only to satisfy you pride with good results, you’ll look a bit closer at the points where you scored poorly. Perhaps there is room for improvement, perhaps even in a totally different direction than the benchmark originally suggested.
I will extend this list perhaps (depends on feedback). Give me some time please to figure out if I can enable comments on it or perhaps Wikify it.
