[Oberon] Protocols (interfaces) in Oberon-2
Andreas Pirklbauer
andreas_pirklbauer at yahoo.com
Sun Oct 25 18:44:27 CET 2020
> Andreas, in your scheme can you create separate protocols, for example
> "Jsonify" with the method ToJSON and a different protocol "Persistify" with
> the methods "Store" and "Load", and have other records implement one or the
> other or neither or both?
Here is what - I think? - you mean (no multiple inheritance in this example):
MODULE JSONProtocol; (*protocol definition*)
TYPE JSON* = POINTER TO JSONDesc;
JSONDesc* = RECORD data*: ... END ;
PROCEDURE^ (j: Text) ToJSON* (...);
END JSONProtocol;
MODULE PersistProtocol; (*protocol definition*)
TYPE Persist* = POINTER TO PersistDesc;
PersistDesc* = RECORD data*: ... END ;
PROCEDURE^ (p: Persist) Store* (…);
PROCEDURE^ (p: Persist) Load* (...);
END PersistProtocol;
MODULE Client;
IMPORT JSONProtocol, PersistProtocol;
TYPE
JSON* = POINTER TO JSONDesc;
JSONDesc* = RECORD (JSONProtocol.JSONDesc) … END ; (*implements JSONProtocol.JSONDesc*)
Persist* = POINTER TO PersistDesc;
PersistDesc* = RECORD (PersistProtocol.PersistDesc)… END ; (*implements PersistProtocol.PersistDesc*)
PROCEDURE (j: Text) ToJSON* (...);
BEGIN (*implementation of ToJSON*)
END ToJSON;
PROCEDURE (p: Persist) Store* (…);
BEGIN (*implementation of Store*)
END Store;
PROCEDURE (p: Persist) Load* (…);
BEGIN (*implementation of Load*)
END Load;
END Client;
More information about the Oberon
mailing list