SOLID Principles Flashcards
SOLID - S
Single Responsibility Principle
Main idea of Single Responsibility Principle
A class should have just one reason to change.
SOLID - O
Open / Closed Principle
Main idea of Open / Closed Principle
Classes should be open for extension but closed for modification.
SOLID - L
Liskov Substitution Principle
Main idea of Liskov Substitution Principle
When extending a class, remember that you should be
able to pass objects of the subclass in place of objects of
the parent class without breaking the client code.
What means Liskov Substistution Principle
This means that the subclass should remain compatible with
the behavior of the superclass. When overriding a method,
extend the base behavior rather than replacing it with some-
thing else entirely.
What Liskov Substitution Principle states about method parameters
Parameter types in a method of a subclass should match or be
more abstract than parameter types in the method of the super-
class
What Liskov Substitution Princliple states about method return types
The return type in a method of a subclass should match or be
a subtype of the return type in the method of the superclass
What Liskov Substitution Principle states about throwning exceptions
A method in a subclass shouldn’t throw types of exceptions
which the base method isn’t expected to throw
What Liskov Substitution Principle states about pre-conditions
A subclass shouldn’t strengthen pre-conditions
What Liskov Substitution Principle states about post-conditions
A subclass shouldn’t weaken post-conditions
What Liskov Substitution Principle states about invariants
Invariants of a superclass must be preserved
What Liskov Substitution Principle states about private fields
A subclass shouldn’t change values of private fields of the
superclass
SOLID - I
Interface Segregation Principle