Created
May 28, 2018 20:44
-
-
Save Mardiniii/bd20bd9d822f596e0e2e819b6f579762 to your computer and use it in GitHub Desktop.
Liskov Sustitution Principle: Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Violates LSP | |
class Company | |
def hire_people | |
expand_the_team | |
end | |
def open_new_location | |
create_a_new_office | |
end | |
def make_money | |
"$$$$$" | |
end | |
end | |
class Corporation < Company | |
def stock_sale | |
call_more_stock_holders | |
end | |
end | |
# Enforces LSP | |
class Company | |
def hire_people | |
expand_the_team | |
end | |
def open_new_location | |
create_a_new_office | |
end | |
def make_money | |
"$$$$$" | |
end | |
def stock_sale | |
raise NotImplementedError | |
end | |
end | |
class Corporation < Company | |
def stock_sale | |
call_more_stock_holders | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment