Relationships and dispatch
What is dynamic dispatch?
On this page
Dynamic dispatch selects an implementation using runtime information about the receiver, and in some languages additional arguments. A Java reference typed as Shape can call draw() on a Circle and run Circle’s override. Compiler optimisations can eliminate the lookup while preserving that observable behaviour.
Worked example
Pythonclass Notice:
def subject(self):
return "Update"
def header(self):
return "Subject: " + self.subject()
class Reminder(Notice):
def subject(self):
return "Renewal due"
assert Reminder().header() == "Subject: Renewal due"Explore class relationships in the OOP Playground