Created
January 1, 2015 02:09
-
-
Save meaganewaller/e343f72d9197a7dc5ac9 to your computer and use it in GitHub Desktop.
liskov substitution principle
This file contains 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
shapes = [Square.new, Rectangle.new] | |
def set_rectangle_width(shapes) | |
shapes.each do |shape| | |
shape.width = 5 | |
shape.height = 6 | |
end | |
end |
This file contains 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
class Rectangle | |
attr_accessor :width, :height | |
end | |
class Square | |
attr_accessor :side | |
def height=(height) | |
@side = height | |
end | |
def width=(width) | |
@side = width | |
end | |
def width | |
@side | |
end | |
def height | |
@side | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment