Search code examples
adaoberon

How is inheritance implemented in Ada and does it have built in GUI?


Does Ada come with built-in GUI, and does it have the same unique approach to inheritance as does Oberon?


Solution

  • No, Ada does not come with a built-in GUI; but then the closest language that I can think of is PostScript. (Technically, the Java-language does not; though its included library does.) That being said there is a GTK binding (which I haven't used at all) and an OpenGL binding (that I've only played with; and to be honest the OpenGL binding is far thinner a binding than I'd like).

    Oberon's inheritance model (as I understand) is single-extension inheritance which is the same as Ada; though Ada does incorporate an Interface system similar to Java. I haven't actually used Oberon, so I can't really provide you with a side-by-side examples for the two, but can show you an example of Ada's.

    Base:

    Type Base is Abstract Tagged Record
       Null;
    End Record; -- Base
    
    -- Base Operations
    Procedure Op( Object : In Out Base );
    Procedure Dispatching_Op( Object : In Out Base'Class );
    

    Extension:

    Type Extended is New Base With Record
      Null;
    End Record; -- Extended
    
    Overriding Procedure Op( Object : In Out Extended );
    

    With bodies of, say:

      Procedure Op( Object : In Out Base ) is
      begin
         Put( "Hello" );
      end Op;
    
      Procedure Dispatching_Op( Object : In Out Base'Class ) is
      begin
         Op( Object );
         Put_Line( " World." );
      end Dispatching_Op;
    
      Procedure Op( Object : In Out Extended ) is
      begin
         Put( "Goodbye" );
      End Op;
    

    Which given an object of type P {P : K.Base'Class:= K.Extended'(Others => <>);} could be called like so:

    P.Dispatching_Op;
    

    And would produce the following results in this instance:

    Goodbye World.