This is a draft cheat sheet. It is a work in progress and is not finished yet.
Principles
Single Responsibility |
A class should have only one reason to change |
Open / Close principle |
Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification |
Liskov Substitution Principle |
Subtypes must be substitutable for their base types |
Interface Segregation Principle |
Clients should not be forced to depend on methods they do not use. |
Dependency Inversion Principle |
High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend upon details. Details should depend upon abstractions |
Command Query Separation |
A method should either be a command or a query |
Do not Repeat Yourself (DRY) |
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system |
General
Boy Scout Rule |
Leave the campground cleaner than you found it |
Keep it Simple, Stupid (KISS) |
Simpler is always better. Reduce complexity as much as possible |
Positive Conditionals |
Positive conditionals are easier to read than negative conditionals |
Don’t Be Arbitrary |
Design
Prefer Polymorphism To If/Else or Switch/Case |
Prefer composition over inheritance |
Prefer Dedicated Value Objects to Primitive Types |
Instead of passing primitive types like strings and integers, use dedicated primitive types: e.g. Uri instead of string |
Vertical Separation |
Variables and methods should be defined close to where they are used |
Encapsulate Conditionals |
if (this.ShouldBeDeleted(timer)) is preferable to if (timer.HasExpired && !timer.IsRecurrent) |
(-) Method with Too Many Arguments |
Prefer fewer arguments. Maybe functionality can be outsourced to a dedicated class that holds the information in fields |
(-) Method with Out/Ref Arguments |
Prevent usage. Return complex object holding all values, split into several methods |
(-) Obscured Intent |
Too dense algorithms that lose all expressiveness |
(-) Magic Numbers / Strings |
Replace Magic Numbers and Strings with named constants to give them a meaningful name when meaning cannot be derived from the value itself |
(-) Dead code / dead comment |
Delete unused things. You can find them in your version control system |
|