Pre-assessment notes

Polymorphism

The answers to this one really showed up that I need to find a way to get more on OO principles into the Inf1OP class... which was on my todo list anyway.

Here's someone with the right top-level view:

You've actually encountered two different kinds of polymorphism in the first year, and both of them occur in Java. The one you see where Java uses generics, e.g. ArrayList<String>, ArrayList<Integer>, is called parametric polymorphism, and Haskell also uses this extensively. (In fact, Java didn't have this kind in the beginning, and our very own Phil Wadler was instrumental in getting it added.) However, the main one is what's usually called object oriented polymorphism, or sometimes ad hoc polymorphism. It's when the same client code can work with objects that have many forms, because they share a common interface which is all the client code needs to know. For example, if a client is written in terms of Animal and only needs to access methods that are understood by any Animal, then the same client code can work with any object which is an instance of a subclass of Animal: And this still applies if subclasses implement methods differently, though note that it's still polymorphism if they don't (e.g., if one subclass of Animal just added an attribute and/or method that the client code never mentioned): Several people mentioned method overloading, but that isn't really a kind of polymorphism, so I'd say these are wrong, though well done for remembering this feature of Java: This, coming from someone who didn't seem to be taking the preassessment totally seriously, was my favourite.
This page is maintained by Perdita Stevens (perdita@inf.ed.ac.uk)


Home : Teaching : Courses : Seoc : 2014_2015 : Preassessment 

Informatics Forum, 10 Crichton Street, Edinburgh, EH8 9AB, Scotland, UK
Tel: +44 131 651 5661, Fax: +44 131 651 1426, E-mail: school-office@inf.ed.ac.uk
Please contact our webadmin with any comments or corrections. Logging and Cookies
Unless explicitly stated otherwise, all material is copyright © The University of Edinburgh