Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Oberon (programming language)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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!
==Object orientation== Oberon supports extension of record types for the construction of abstractions and heterogeneous structures. In contrast to the later dialects, Oberon-2 and Active Oberon, the original Oberon lacks a dispatch mechanism as a language feature but has it as a programming technique or design pattern. This gives great flexibility in OOP. In the Oberon operating system, two programming techniques are used together for the dispatch call: Method suite and Message handler. ===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. ===Message handler=== This technique consists of replacing the set of methods with a single procedure, which discriminates among the various methods: '''MODULE''' Figures; ''<span style="color: gray">(* Abstract module *)</span>'' '''TYPE''' Figure* = '''POINTER TO''' FigureDesc; Message* = '''RECORD END'''; DrawMsg* = '''RECORD''' (Message) '''END'''; ClearMsg* = '''RECORD''' (Message) '''END'''; MarkMsg* = '''RECORD''' (Message) '''END'''; MoveMsg* = '''RECORD''' (Message) dx*, dy* : '''INTEGER''' '''END'''; Handler* = '''PROCEDURE''' (f : Figure; '''VAR''' msg : Message); FigureDesc* = '''RECORD''' ''<span style="color: gray">(* Abstract *)</span>'' handle : Handler; '''END'''; '''PROCEDURE''' Handle* (f : Figure; '''VAR''' msg : Message); '''BEGIN''' f.handle(f, msg) '''END''' Handle; '''PROCEDURE''' Init* (f : Figure; handle : Handler); '''BEGIN''' f.handle := handle '''END''' Init; '''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 : INTEGER; '''END'''; '''PROCEDURE''' Draw* (r : Rectangle); '''BEGIN''' ''<span style="color: gray">(* ... *)</span>'' '''END''' Draw; ''<span style="color: gray">(* Other procedures here *)</span>'' '''PROCEDURE''' Handle* (f: Figure; '''VAR''' msg: Figures.Message); '''VAR''' r : Rectangle; '''BEGIN''' r := f(Rectangle); '''IF''' msg '''IS''' Figures.DrawMsg '''THEN''' Draw(r) '''ELSIF''' msg '''IS''' Figures.MarkMsg '''THEN''' Mark(r) '''ELSIF''' msg '''IS''' Figures.MoveMsg '''THEN''' Move(r, msg(Figures.MoveMsg).dx, msg(Figures.MoveMsg).dy) '''ELSE''' <span style="color: gray">(* ignore *)</span> '''END''' '''END''' Handle; '''PROCEDURE''' New* ('''VAR''' r : Rectangle); '''BEGIN''' '''NEW'''(r); Figures.Init(r, Handle) '''END''' New; '''END''' Rectangles. In the Oberon operating system both of these techniques are used for dynamic dispatch. The first one is used for a known set of methods; the second is used for any new methods declared in the extension module. For example, if the extension module Rectangles were to implement a new Rotate() procedure, within the Figures module it could only be called via a message handler.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Oberon (programming language)
(section)
Add topic