Programming Techniques of MixJuice

Here is a list of the programming techniques of MixJuice used to improve design patterns.

Method extension

The behavior of existing methods can be extended by overriding.

structure-08-07:c01

module original {
  define class C {
    define void m(){...}
  }
}
module extension extends original {
  class C {
    void m(){ original(); ...}
  }
}

Super-interface addition

New super-interfaces can be added to existing classes. In other words, existing classes can become subtype of new interfaces.

structure-08-07:c02

module original {
  define class C {...}
  define interface I {...}
}
module extension extends original {
  class C implements I {...}
}

Field addition

New fields can be added to existing classes.

structure-08-07:c03

module original {
  define class C {...}
}
module extension extends original {
  class C {
    int newField;
  }
}

Method addition

New methods can be added to existing classes.

structure-08-07:c04

module original {
  define class C {...}
}
module extension extends original {
  class C {
    define void newMethod(){...}
  }
}

Class extension

The combination of Super-interface addition, Method addition and Field addition.

Abstract method addition

New abstract method can be added to existing abstract classes. Implementation methods corresponding to the added abstract method should be added to all non-abstract subclasses to make the program executable.

structure-08-07:c05

module original {
  define abstract class S {...}
  define class A extends S {...}
  define class B extends S {...}
}
module extension extends original {
  class S {
    define abstract void newMethod();
  }
  class A {
    void newMethod(){...}
  }
  class B {
    void newMethod(){...}
  }
}

Namespace separation

Programmers can make the boundaries of information hiding independent of class boundaries. From the viewpoint of the programmer who defines names, arbitrary groups of names can be provided. From the viewpoint of the client of the defined names, arbitrary groups can be selected to use.

structure-08-07:c06

module namesA {
  define class A1 {...}
  define class A2 {...}
  ...
}
module namesB {
  define class B1 {...}
  define class B2 {...}
  ...
}
module clientOfA extends namesA { ... }
module clientOfB extends namesB { ... }
module clientOfBothAandB  extends namesA, namesB { ... }

Separation of specifications and implementations

A class can be defined as two separate modules. One module is called the specification module, which only defines the external interface of the class using abstract constructors and abstract methods; and the other is called the implementation module, which defines the internal implementation of the class.

module c {
  define class C {
    // public methods
    define abstract void m1();
    define abstract void m2();
  }
}
module c.implementation extends c {
  class C {
    // public methods
    void m1(){...}
    void m2(){...}
    // protected fields and methods
    int f1;
    define void m3(){...}
  }
}

Implementation selection

At the link time, the user can select one implementation module from more than one different implementation modules. (The user should be careful to select just one implementation module of a class to avoid conflicts of modules. Current implementation of the MixJuice linker does not report an error even if more than one implementation modules of a class are selected.)

structure-08-07:c08

module m {
  define class C {  // NOTE: C is a non-abstract class.
    define abstract void m();
  }
}
module m.implementationA extends m {
  class C {
    void m(){...}
  }
}
module m.implementationB extends m {
  class C {
    void m(){...}
  }
}

Akira TANAKA <akr@m17n.org>, Yuuji ICHISUGI <y-ichisugi@aist.go.jp>

Top