Liskov substitution principle (LSP)

"If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T."                                                                                                                    -Barbara Liskov

After reading that three times, I am still not sure I have got it straight. Thankfully, Robert C. Martin made it easier on us and summarized it as follows:

"Subtypes must be substitutable for their base types."                                                                                     -Robert C. Martin

That I can follow. However, isn't he talking about abstract classes ...

Get Hands-On Dependency Injection in Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.