• Post Reply Bookmark Topic Watch Topic
  • New Topic

Polymorphism terminology questions.  RSS feed

 
Grant Robertson
Ranch Hand
Posts: 36
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a question about terminology, not about how things work.

Is there a short term that means: "using an object reference with the datatype of a supertype to refer to an object with the datatype of a subtype"?

Saying "polymorphic reference" doesn't seem to be specific enough because ALL references other than those with the Object datatype are polymorphic. I saw one post that referred to these reference variables as a "supertype reference." In the absence of any other (more official) term, I may just use that term because calling a reference a "supertype reference" implies that there is a subtype. It sure beats what I was thinking about using: "sub-as-super." Which, when the inevitable mispronunciations occur, would lead to all kinds of off-color jokes.

What do you all think? Is there an "official" term that all of the dozens of Java books I have read seem to have missed? Or does everyone stumble along, spelling things out with a nearly sentence-long phrase.
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The closest I can think of is 'programming to interface', or in long hand 'programming to interface rather than implementation'.

This refers for example to situations where you make your variable a List rather than an ArrayList, or a Map rather than a HashMap.

I don't think its an 'official' term as such though.

Have you got an example of a sentence where you want to use this phrase?
 
Grant Robertson
Ranch Hand
Posts: 36
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Because myAnimal is a supertype reference, we cannot be sure of exactly what subtype object it may hold a reference to. Therefore, we may need to cast the reference down to a more specific subtype before calling any methods on it."

"Just use the supertype reference as the type parameter for your generic class so you can use it to manipulate all of its subtypes."
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usage you are referring to is related to the Liskov Substitution Principle or LSP, just so you know. It is named after Barbara Liskov, who co-developed it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!