[Tutor] feedback on simple python code

Danny Yoo dyoo at hashcollision.org
Mon Feb 27 22:00:04 EST 2017


Hi Ryan,

Let's take a look...

Overloading the "write" method to take in different types of arguments
looks a bit suspicious.


You have a superclass that defines a write method, and you have two
subclasses that implement that method.  However, your first
implementation, LogFile.write, appears to take in a string, while the
second, DelimWrite.write,  appears to take a list of strings.

That's what looks somewhat problematic.  According to inheritance
rules, the methods of subclasses should be able to take the same kind
of input as specified in the superclass.  You can read more about this
in https://en.wikipedia.org/wiki/Liskov_substitution_principle, but
it's roughly saying that if you have a superclass, subclass methods
should do their thing on the same kind of data.  Violating this can
lead to code that is hard to understand.

To solve this: I'd recommend normalizing the input if you have that
option.  If you can make the input always be a list of strings, that
would be one way to resolve this problem.  Alternatively, if you can
make the input always be a single string, then that would solve this
problem too.


Please feel free to ask questions.  Good luck!


More information about the Tutor mailing list