Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polymorphic Reference & Methods

 
Bronson King
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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.
 
Henry Wong
author
Marshal
Pie
Posts: 20889
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps if you post some code it will make it easier to understand
 
Keith Flo
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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:

.
 
Nuwan Hettiarachchi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Nuwan H",
Please check your private messages regarding an important administrative matter.
-Ben
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic