Hello, my name is Dmitry Karlovsky. And you're on Core Dump , where we take different topics from computer science and deconstruct them piece by piece. This time, we'll start deconstructing the SOLID principles starting with the most concrete.
Back in 1987, Barbara Liskov formulated the principle of developing a name for herself.
Liskov Substitution Principle
It allows you to understand whether you have written polymorphic code correctly or not. But before formulating it, we need to understand some of the concepts that are included in the definition.
Video recording of this analysis .
Supertype-subtype relationship
All data in our program belongs to one type or another. The type defines the set of possible values ββand their semantics. One type can completely include another. In such a case, the second type is a subtype of the first. In this way, types can form a hierarchy. Let's look at an example with numbers ..
Both the type of integers and the type of positive numbers are separately special cases of the type of real numbers, and therefore are its subtypes. At the same time, wholes do not include all positive ones. And the positive ones do not include all wholes. Therefore, these types do not belong to each other in a supertype-subtype relationship. But natural numbers are both integers and positive, so the type of natural numbers is a subtype of both of these types.
"-" , , β , .
. , . . , , β , .
, , .
β .
, draw
. β .
LSP β
, : " , , , ".
, , , , , . , LSP : , .
, ...
LSP
, -, , .
, , "", . . , , . LSP. , . "".
, , , . ..
- β ( )
- β ( )
- :
- ( )
- ( )
, , LSP .
LSP
- . , , , , LSP . β .
, , , .
LSP
, LSP , ...
" , , , ".
, , β . , , .
LSP?
, , LSP. , , , . , - , . , .
LSP, , β , . . , .
- LSP :-(
- :-)
?
. , , .
:
, . - . - . - . , , , .
..
-
If this analysis seemed useful to you, then let me know about it through the like. And also share a link to it with your colleagues.
If you disagree with any thought or, conversely, feel some kind of understatement and want to add your own ideas, then I look forward to your comments.
If you are not afraid to discuss with me on the air, or are even ready to become a co-author of future analyzes, then write telegrams .
Finally, subscribe to the channel so you don't miss further insights. We still have a lot to discuss with you.
That's all for now. With you was a little programmer Dmitry Karlovsky.