Monday, January 12, 2015

Changes 1/12/15 - Liskov corrections, Bottle stuff

After the post I made on Friday (1/9/15), Kevin emailed me to clarify some Liskov Substitution stuff.

First of all, shout out to Kevin for reading my blog:


He wanted to make sure it was clear that you need to look at the specification rather than the implementation of a method in order to verify that a subclass method does not violate the LSP.

Kevin gave three examples of the same method with different specification. In the first two examples, #get_number has been stubbed out (given a return value that fits its expected behavior without actually containing any functionality). We need to look at the specification for the method, not the implementation, for clues on obeying LSP.

Implementation 1:
In this example, it is easy to define a subclass that obeys the LSP - you just need to implement it such that the range of possible outputs for #get_number is less than or equal to the numbers 0 to 100.

Implementation 2:
Just like in Implementation 1, a subclass overriding #get_number would need to take into account the specification given in the method.

Implementation 3:
In this example, it is impossible to determine what is expected of a subclass' overridden method--there is nothing to go off of. This is very bad! Obviously the method is expected to be overridden but offers no other information.

Also, for the record, I didn't come up with all this on my own, I pretty much just paraphrased Kevin's email.  I think I definitely understand the concept better now.

He also put this in the email, and I thought it was worth sharing:

Today I also helped Aki and Dylan with some Bottle stuff. They're trying to push HTML form data into an sql database using Bottle, which is something I did in math-drill last year. I showed them my code as an example, but unfortunately it's a bit more complex than what they need. My code actually generates the form using python, which isn't something they need to worry about and just makes it harder for them to understand. If they need my help, hopefully they'll ask...

1 comment:

  1. OK, Alex, the Cobert video was a great touch, and yes, a double shout out to Kevin for reading your blog! Finding mentors like Kevin is key to having a top rate educational experience like the one you have been privileged to experience thanks to him. I had never heard of the Liskov substitution principal until you started discussing it with Kevin.

    Thanks for the link to math-drill code. You're right, it is too much to be used as a first example for what they are trying to do. I referred them to the bottle zoo, which has examples which increase in complexity at a very modest pace.

    ReplyDelete