9. –Michael C. Feathers, Working Effectively with Legacy Code
“Code without tests is bad code. It doesn't
matter how well written it is; it doesn't matter
how pretty or object-oriented or well-
encapsulated it is. With tests, we can change
the behavior of our code quickly and verifiably.
Without them, we really don't know if our code
is getting better or worse.”
31. - Barbara Liskov
“Let phi(x) be a property provable about
objects x of type T. Then phi(y) should be true
for objects y of type S where S is a subtype of
T.”
32. class Rectangle(object):
def __init__(self, width, height):
self.width = width
self.height = height
def area(self):
return self.width * self.height
class Square(Rectangle):
def area(self):
return self.height * self.height
def much_code():
my_shape = factory.rectangle(10, 5)
my_shape.area() # I expect this to be 50
33. If you change the references
from base classes to child
classes, the tests should pass.
34.
35. class Rectangle(object):
def __init__(self, width, height):
self.width = width
self.height = height
def area(self):
return self.width * self.height
class Square(Rectangle):
def area(self):
return self.height * self.height
def much_code():
my_shape = factory.rectangle(10, 5)
my_shape.area() # I expect this to be 50