LSP vs OCP / Liskov Substitution VS Open Close
Posted
by
Kolyunya
on Programmers
See other posts from Programmers
or by Kolyunya
Published on 2012-12-06T09:31:22Z
Indexed on
2012/12/06
11:22 UTC
Read the original article
Hit count: 378
I am trying to understand the SOLID principles of OOP and I've come to the conclusion that LSP and OCP have some similarities (if not to say more).
the open/closed principle states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification".
LSP in simple words states that any instance of Foo
can be replaced with any instance of Bar
which is derived from Foo
and the program will work the same very way.
I'm not a pro OOP programmer, but it seems to me that LSP is only possible if Bar
, derived from Foo
does not change anything in it but only extends it. That means that in particular program LSP is true only when OCP is true and OCP is true only if LSP is true. That means that they are equal.
Correct me if I'm wrong. I really want to understand these ideas. Great thanks for an answer.
© Programmers or respective owner