{
  ex8.s

  Contents:

     1. a reflective(extension) class Window;
     2. a reflective(extension) class MacWindow that inherits from Window;
     3. an extension class Border whose allowed set contains
        Window.

  Tests:
     1. how subclasses are affected when an extension is put in a
        superclass;
     2. message sends to "object"  in extension classes;
     3. message sends to "super" in subclasses.


  }

reflective(extension) class Window
  private:
    var width, height : integer;
  public:
    proc draw()
      begin
      write(100);
      end
    proc m()
      begin
      write(150);
      end
endclass

reflective(extension) class MacWindow inherits Window
  public:
    proc draw()
      begin
      write(200);
      super.draw();      // Window.draw() before and Border.draw() after
      super.m();         // Window.m() before and Border.m() after
      end
endclass


extension class Border(Window)
  private:
    var size : integer;
  public:
    proc draw()
      begin
      object.draw();
      write(size);
      size = 12;
      end
    proc m()
      begin
      write(300);
      end
endclass


class Program
  public:
    proc run()
        var
          w  : Window;
          mw : MacWindow;
    begin
    w = Window.new();
    mw = MacWindow.new();
    w.draw();       // Window::draw()
    mw.draw();      // MacWindow::draw()
    if Reflect.attachExtension(Window, Border) == 0
    then
      w.draw();     // Border::draw()
      w.draw();     // Border::draw()
      w.m();        // Border::m()
      w.m();        // Border::m()
      mw.draw();    // MacWindow::draw()
      mw.draw();    // MacWindow::draw()
      mw.m();       // Border::m()
      mw.m();       // Border::m()
      if Reflect.removeExtension(Window) == 0
      then
        w.draw();   // Window::draw()
        w.draw();   // Window::draw()
        mw.draw();  // MacWindow::draw()
        mw.draw();  // MacWindow::draw()
        mw.m();     // Window.m()
        mw.m();     // Window.m()
      endif
    endif
    end
endclass

