layers method
  • CompInt -- compresses interface extension hierarchies
  • end layers method chapterLinks method
  • Interface extension specifications
  • end chapterLinks method

    Specifying Interfaces and Interface Extensions

    PJ expects a file containing a base interface to have the following format:

    package <package-name>;
    [<import-statements>]
    <java-interface-declaration>

    Note:

    An interface extension file has the following format:

    package <package-name>;
    [<import-statements>]
    [<modifiers>] extends interface <name> [ extends <interface-list> ] { [body] }

    Note:

    Rules of Composition

    Composition of a base interface with an extension (or an extension interface with another extension interface) follows simple rules:

    An example of a base interface file and an extension interface file are:

    package IBase1;
    
    import x.y.z.*;
    import java.io.Serializable;
    
    interface MyInt extends FooInterface {
        int Silent = 0;
        void foo() throws AFit;
        SomeType bar( int x );
    }

    package Iext1;
    
    import java.io.Serializable;
    
    public transient extends interface MyInt extends yyy, java.io.Serializable {
       int Terse = 2;
       void foo() throws SomeException;
       int increment( int i );
    }

    The result of their composition is shown below.  Highlighted in yellow are additions made by the MyInt extension.

    package IBase1;
    
    import x.y.z.*;
    import java.io.Serializable;
    
    public transient interface MyInt extends FooInterface, yyy, java.io.Serializable {
        int Silent = 0;
        int Terse = 2;
        void foo() throws AFit, SomeException;
        SomeType bar( int x );
        int increment( int i );
    }

    Type sorting is a linear algorithm (which is invoked by the -t option to PJ) that sorts the declarations within an interface.  To understand the motivation for type sorting, consider the result of the above composition if type sorting is not used (see below): it is a jungle of definitions that are hard to understand.  Type sorting collects all variable definitions together in one spot and method definitions in another, and makes a small contribution to generated code beautification.

    public transient interface MyInt extends FooInterface, yyy, java.io.Serializable {
        int Silent = 0;
        void foo() throws AFit, SomeException;
        SomeType bar( int x );
        int Terse = 2;
        int increment( int i );
    }

    Again, it is possible to compose two interface extension files to produce a composite extension file.  Remember: a base file is a "constant" and an extension file is a "function" in GenBorg.  So composing a constant with a function (e.g., f(a)) produces a constant -- i.e., composing a base interface with an extension produces a composite base interface.  Similarly, composing a function in GenBorg with another function yields a function.  That is, composing an interface extension with another interface extension yields a composite interface extension.

    The New and Overrides Modifiers

    A convenient and optional feature is to designate methods of an extension by the modifiers "new" or "overrides".  "new" means that the extension is defining a new method whose name should not be used by a method in the base interface.  "overrides" means that the extension is defining an extension to a previously defined method. PJ generates an error if it detects that the conditions for "new" or "overrides" are not satisfied.  As an example:

    package Iext0;
    
    extends interface MyInt extends java.io.Serializable {
        overrides void foo() throws SomeException;
        new void barrr();
    }

    The above interface defines a new method (barrr) that and overrides a previously defined method (foo)

    The use of "new" and "overrides" makes a useful contribution to avoiding inadvertent capture; these modifiers should be used to guarentee that a method being defined by an extension is in fact a new method or does override an existing method.

    end chapters method