Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Oberon (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Method suite=== In this technique, a table of [[Subroutine|procedure]] [[Variable (computer science)|variables]] is defined and a [[global variable]] of this type is declared in the extended module and assigned back in the generic module: '''MODULE''' Figures; ''<span style="color: gray">(* Abstract module *)</span>'' '''TYPE''' Figure* = '''POINTER TO''' FigureDesc; Interface* = '''POINTER TO''' InterfaceDesc; InterfaceDesc* = '''RECORD''' draw* : '''PROCEDURE''' (f : Figure); clear* : '''PROCEDURE''' (f : Figure); mark* : '''PROCEDURE''' (f : Figure); move* : '''PROCEDURE''' (f : Figure; dx, dy : '''<span style="color: darkblue">INTEGER</span>'''); '''END'''; FigureDesc* = '''RECORD''' if : Interface; '''END'''; '''PROCEDURE''' Init* (f : Figure; if : Interface); '''BEGIN''' f.if := if '''END''' Init; '''PROCEDURE''' Draw* (f : Figure); '''BEGIN''' f.if.draw(f) '''END''' Draw; ''<span style="color: gray">(* Other procedures here *)</span>'' '''END''' Figures. We extend the generic type Figure to a specific shape: '''MODULE''' Rectangles; '''IMPORT''' Figures; '''TYPE''' Rectangle* = '''POINTER TO''' RectangleDesc; RectangleDesc* = '''RECORD''' (Figures.FigureDesc) x, y, w, h : '''<span style="color: darkblue">INTEGER</span>'''; '''END'''; '''VAR''' if : Figures.Interface; '''PROCEDURE''' New* ('''VAR''' r : Rectangle); '''BEGIN''' '''<span style="color: darkblue">NEW</span>'''(r); Figures.Init(r, if) '''END''' New; '''PROCEDURE''' Draw* (f : Figure); '''VAR''' r : Rectangle; '''BEGIN''' r := f(Rectangle); ''<span style="color: gray">(* f AS Rectangle *)</span>'' ''<span style="color: gray">(* ... *)</span>'' '''END''' Draw; <span style="color: gray">(* Other procedures here *)</span> '''BEGIN''' ''<span style="color: gray">(* Module initialisation *)</span>'' '''<span style="color: darkblue">NEW</span>'''(if); if.draw := Draw; if.clear := Clear; if.mark := Mark; if.move := Move '''END''' Rectangles. [[Dynamic dispatch]] is only done via procedures in Figures module that is the generic module.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)