[Oberon] Protocols (interfaces) in Oberon-2

Andreas Pirklbauer andreas_pirklbauer at yahoo.com
Sun Oct 25 18:55:25 CET 2020


Correction: JSON instead of Text of course:

————————

MODULE JSONProtocol;  (*protocol definition*)
    TYPE JSON* = POINTER TO JSONDesc;
      JSONDesc* = RECORD data*: ... END ;
      PROCEDURE^ (j: JSON) 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: JSON) 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