• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Polymorphic Reference & Methods

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to verify that this restaurant analogy I wrote in my notes is 100% correct...

The reference type provides the menu, but the object type cooks the meals.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bronson King:
The reference type provides the menu, but the object type cooks the meals.



I don't have a clue what this statement means, much less if it works as an analogy.... but I am getting hungry...

Henry
 
Bronson King
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically trying to burn in that only methods the reference type knows about are available, even though the actual object's method is going to be run.

The analogy works too because a cook(object) might know some dishes(his own methods) that aren't on the menu(reference) and also might put his special touches(overrides) on the available meals(methods).

Sorry if I've confused anyone, but I think I've burned this in in the process.

Bon appetit!
[ May 25, 2008: Message edited by: Bronson King ]
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps if you post some code it will make it easier to understand
 
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I like the analogy .. and you're right ... although only methods that the reference type knows about can be called (or referenced) ... what actually gets executed at run time is the implementation defined by the object being referenced. For example:

.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

My favourite analogy is to match the TV remote control with the TV.
TV remote control is the Reference Type,
TV is the actual object.

If TV remote has switches to operate the TV will function accordingly as the instruction (methods) implemented at run time.

You can add the Casting operations in the same analogy and get this story expanded. The advantage is once you know the story, it is easy to map it back to the real OBJECTS.

cheers!

Nuwan
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Nuwan H",
Please check your private messages regarding an important administrative matter.
-Ben
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic