Lecture overview -- Keyboard shortcut: 'u'  Previous page: The interpretation of  <kbd>self</kbd> -- Keyboard shortcut: 'p'    Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Lecture 8 - Page 11 : 11
Functional Programming in Scheme
Object-oriented programming in Scheme
A demo of virtual methods

On this page we will make two artificial classes with the purpose of demonstrating virtual methods

y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/class-x-y-allA base class x .

The method res sends the message get-state to itself. If an x object receives the message res , it will return the number 1.

y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/class-x-y-allA class y that inherits from x .

The y class redefines the method get-state . The y class inherits the method res . If a y method receives the message res , it will be propagate to the x part of the object. Due to the use of virtual methods, self in the x part refers to the y part. Therefore the get-state message returns the y-state of the y part, namely 2.

y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/class-x-y-dialogueA dialogue using class x and class y.

Instances of the classes x and y are created and res messages are send to both of them.

y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/class-x-y-allThe functions new-instance and virtual-operations.


y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/class-x-y-allAll the stuff necessary to play with x and y.

The crucial observation is that the y object bound to the variable b returns the number 2 when we send it the res message.

Go to exerciseRepresenting HTML with objects in Scheme