Dynamic Extensions

    Methods of a class, which includes methods of all objects of that class, can be replaced by methods of a dynamic extension class.

class Window
  public:
    proc init(...)
      begin
      ...
      end
    proc draw()
      ..
    ..
end

   // same syntax as shell classes
 
shell class Border(Window)
  public:
    proc init()
      begin
      end
    proc draw()
      begin
      self.drawBorder();
      super.draw();
      end
  private:
    proc drawBorder()
      ...
end

    The previous code defines a dynamic extension class Border (or just extension Border) that is attached  to a class Window by command

     Meta.attachExtension(Window, Border)

The syntax for dynamic extension classes is the same for shell classes.

An extension is removed by

     Meta.removeExtension(Window)

A complete example of the use of extensions is below.

var w1, w2 : Window;

w1 = Window.new(...);
w2 = Window.new(...);
  // draw windows without borders
w1.draw();
w2.draw();

Meta.attachExtension( Window, Border );

  // draw windows with borders
w1.draw();
w2.draw();

 
var catch : CatchMetaException;

catch#init();
try(catch)
  Meta.removeExtension(Window);
    // draw windows without borders
  w1.draw();
  w2.draw();
end
 
 

What is new ?

    The advantages of dynamic extensions are similar to those of shells: they are easy to understand and efficient. Besides that, we only know one statically type language that allows one change the methods of a whole class: Meta Java. Method interceptAll of shells can also be used with dynamic extensions.
 
Return