Friday, January 9, 2015

Changes 1/9/15 EIMACS and more NSF meetup stuff

Sam, Finn, and I took EIMACS test 23, which was on Sets and Maps.  It was pretty easy.

At NSF, Kevin and I also talked about something he had asked earlier, which was about the EIMACS ListQueue class.  This is the earlier blog post I had written.  When I was thinking of the answers to his questions, I was assuming that the implementation of ListQueue was empty (the first implementation I listed in this post), whereas Kevin was thinking of the second implementation listed in that post, where methods of LinkedList are actually overridden.

It turns out that the class, even with the listed overriden methods, does fulfill the Liskov substitution principle, because the re-implemented methods have the exact same functionality as the parent methods as defined in LinkedList.

Kevin also mentioned that in order to fulfill this prinicple, the range of valid inputs for your method should be larger than that of the method you are overriding, while the range of outputs should be the same or smaller than the overridden method.  This prevents code that is using your object as though it is its superclass (for example, calling code expecting a LinkedList<Object> and passing in a ListQueue) from being "surprised" by differences in functionality.

A concrete example of this:
The NarrowNumberGenerator has a narrower range of outputs (0 to 5 inclusive) than its parent, so a class which uses a NarrowNumberGenerator in place of a NumberGenerator doesn't need to worry about the differences in behavior.  All the outputs of NarrowNumberGenerator are also valid outputs of NumberGenerator.

1 comment:

  1. Please forward the email Kevin sent you about this post to Finn and Sam. I had to look up the Liskov substitution principal (good idea to make those things links to wikipedia entries - http://en.wikipedia.org/wiki/Liskov_substitution_principle). It was interesting to me to look up who this principal is named by, Barbara Liskov (http://en.wikipedia.org/wiki/Barbara_Liskov). Check out her PhD thesis advisor, John McCarthy, a giant in the history of computer science. Cool stuff!

    ReplyDelete