A compilation of two Object Oriented Programming and Design cheat sheets already in the website.
Type-Checking ⇒ State/Strategy
Conditional ⇒ Polymorphism
Move/Rename Method or Field
Move to Superclass/Subclass
Basic OO Terms
The process of separating ideas from specific instances of those ideas at work.
The provision of a single interface to entities of different types. Subtyping.
When an object or class is based on another object or class, using the same implementation; it is a mechanism for code reuse. The relationships of objects or classes through inheritance give rise to a hierarchy.
Enclosing objects in a common interface in a way that makes them interchangeable, and guards their states from invalid changes.
DRY - Don’t repeat yourself
Duplication should be abstracted
"Don't call us, we'll call you"
YAGNI - You Ain't Gonna Need It
Only code what you need now
KISS - Keep it simple, stupid!
Favor clarity over cleverness
Law of Demeter
Only talk to related classes
Convention Over Configuration
Defaults cover 90% of uses
What happens in Vegas...
Design By Contract
And then write tests
Minimize the dependencies
Common Closure Principle
Classes that change together, stay together
Avoid Premature Optimization
Don’t even think about optimization unless your code is working
Separation of Concerns
Different functionalities are distinctly managed
Expect and welcome any changes
Encapsulate what varies
Code to an interface rather than to an implementation
Each class in your application should have only one reason to change
Classes are about behavior and functionality
Favor the following over inheritance
When you hand over the responsibility for a particular task to another class or method.
Use behavior from a family of other classes, and change that behavior at runtime.
When one class is used as part of another class, but still exists outside of that other class.
Only inside the same class instance
Inside same or derived class instances
All other classes linking/referencing the class
Only other classes in the same assembly
All classes in same assembly, or derived classes in other assembly
Accessible on the class itself (can combine with other accessors)