Skip to content

Commit 17fc7ef

Browse files
authored
Update solid.md
1 parent a08942a commit 17fc7ef

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

book/solid.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ Let's check what these mean.
1515

1616
## Single responsibility
1717

18+
A class should have one, and only one, reason to change.
19+
1820
Gather together the things that change for the same reasons. Separate those things that change for different reasons.
1921

2022
## Open-closed
2123

24+
You should be able to extend a classes behavior, without modifying it.
25+
2226
A class or module (a set of related classes) should hide its implementation details (i.e. how exactly things are done) but have a well defined interface that both allows its usage by other classes (public methods) and extension via inheritance (
2327
protected and public methods).
2428

2529
## Liskov substitution
2630

31+
Derived classes must be substitutable for their base classes.
32+
2733
LSP, when defined classically, is the most complicated principle in SOLID. In fact, it's not that complicated.
2834

2935
It is about class hierarchies and inheritance. When you implement a new class extending from base one
@@ -34,11 +40,15 @@ For more see [a good set of answers at StackOverflow](http://stackoverflow.com/q
3440

3541
## Interface segregation
3642

43+
Make fine grained interfaces that are client specific.
44+
3745
The principle points that an interface should not define more functionality that is actually used at the same time. It is like
3846
single responsibiltiy but for interfaces. In other words: if an interface does differnt things, break it into multiple more focused interfaces.
3947

4048
## Dependency inversion
4149

50+
Depend on abstractions, not on concretions.
51+
4252
Dependency inversion basically states that a class should tell what it needs via interfaces but never get what it needs itself.
4353

4454
See [dependencies.md](https://github.com/samdark/yii2-cookbook/blob/master/book/dependencies.md) for more information.

0 commit comments

Comments
 (0)