[Oberon] Protocols (interfaces) in Oberon-2

Luca Boasso luke.boasso at gmail.com
Sun Oct 25 14:27:18 CET 2020


A key feature of protocols / interfaces is the safe multiple inheritance:
you can explicitly or implicitly (like in the Go language) implement
several interfaces and be type compatible with each one of them.

Do you support something like the following?

TextDesc = RECORD (TextProtocol.TextDesc, WriteProtocol.WriterDesc) END ;
(*this means: “implements TextProtocol.TextDesc AND
WriteProtocol.WriterDesc "*)

If this is not supported I don't see this feature being that useful. To
support the feature above the implementation is more complicated than
Oberon-2's bound procedures. See https://research.swtch.com/interfaces for
one way of doing this, or "Efficient implementation of Java interfaces:
Invokeinterface considered harmless"
<http://www.academia.edu/download/42084165/Efficient_Implementation_of_Java_Interfa20160204-28309-28q4h3.pdf>

On Sun, Oct 25, 2020 at 6:46 AM Andreas Pirklbauer <
andreas_pirklbauer at yahoo.com> wrote:

> Correction: In Text1, it’s TextDesc = RECORD (TextProtocol.TextDesc) of
> course
>
> —————————
>
> Protocols (sometimes called interfaces) can be added to
> Oberon-2 without adding any keywords to the language.
>
> This is one of the key differences to how it is usually defined
> and implemented, e.g. in Swift [*] or in Integrated Oberon [**]
>
> Under the new minimalistic design, what distinguishes a protocol
> from an actual implementation (of the class) is that in the protocol
> definition the implementations of the class methods are simply not
> defined. Instead, any module that *imports* a protocol definition
> can “adopt” (i.e. implement) it. See the example below.
>
> An experimental implementation showed that if the language
> is extended in *this* way, the implementation cost is minimal.
>
> But the question is: Is it worth it? Simplicity of implementation
> should of course not be a criteria for adopting a new feature.
>
> Personally, I am rather sceptical of the usefulness of protocols.
> But perhaps someone provides a good reason to adopt them.
>
> -ap
>
>
> Example:
>
>   MODULE TextProtocol;  (*protocol definition*)
>     TYPE Text = POINTER TO TextDesc;
>       TextDesc = RECORD data*: (*text data*) END ;
>       PROCEDURE (t: Text) Insert (string: ARRAY OF CHAR; pos: LONGINT);
>       PROCEDURE (t: Text) Delete (from, to: LONGINT);
>       PROCEDURE (t: Text) Length (): LONGINT;
>   END TextProtocol;
>
>   MODULE Text1; (*one implementation of the Text protocol*)
>     IMPORT TextProtocol;
>     TYPE Text = POINTER TO TextDesc;
>       TextDesc = RECORD (TextProtocol.TextDesc) END ;  (*this means:
> “implements TextProtocol.TextDesc"*)
>
>     PROCEDURE (t: Text) Insert (string: ARRAY OF CHAR; pos: LONGINT);
>     BEGIN (*implementation of Insert*)
>     END Insert;
>
>     PROCEDURE (t: Text) Delete (from, to: LONGINT);
>     BEGIN (*implementation of Delete*)
>     END Delete;
>
>     PROCEDURE (t: Text) Length (): LONGINT;
>     BEGIN (*implementation of Length*)
>     END Insert;
>   END Text1;
>
>
>   MODULE Text2; (*another implementation of the Text protocol*)
>     IMPORT TextProtocol;
>     TYPE Text = POINTER TO TextDesc;
>       TextDesc = RECORD (TextProtocol.TextDesc) END ;  (*this means:
> “implements TextProtocol.TextDesc"*)
>
>     PROCEDURE (t: Text) Insert (string: ARRAY OF CHAR; pos: LONGINT);
>     BEGIN (*implementation of Insert*)
>     END Insert;
>
>     PROCEDURE (t: Text) Delete (from, to: LONGINT);
>     BEGIN (*implementation of Delete*)
>     END Delete;
>
>     PROCEDURE (t: Text) Length (): LONGINT;
>     BEGIN (*implementation of Length*)
>     END Insert;
>   END Text2;
>
>
> [*] https://docs.swift.org/swift-book/LanguageGuide/Protocols.html#
> [**] https://github.com/io-core/technotes/blob/main/technote014.md
>
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20201025/e94a5755/attachment.html>


More information about the Oberon mailing list