Skip to content

Instantly share code, notes, and snippets.

@Mardiniii
Created May 28, 2018 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mardiniii/bd20bd9d822f596e0e2e819b6f579762 to your computer and use it in GitHub Desktop.
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.
# 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