subsections:


hush classes">

Basic hush classes


slide: Basic


    interface kit { 
kit
void eval(string cmd); string result(); void bind(string name, handler h); };


     interface handler { 
handler
int dispatch( event e );
to dispatch events

int operator(); };


     interface widget : handler { 
widget
... void bind( handler h ); void bind( string action, handler h ); ... };


     interface event : handler { 
event
operator(); };


  class A { 
A -- naive
public A() { } public void f1() { System.out.println("A.f1"); f2(); } public void f2() { System.out.println("A.f2"); } };

slide: Running example



  class A { 
A
public A() { body = new BodyOfA(this); } protected A(int x) { } public void f1() { body.f1(); } public void f2() { body.f2(); } public void f3() { System.out.println("A.f3"); } private A body; };

slide: Interface: A



  class BodyOfA extends A { 
BodyOfA -- naive
public BodyOfA() { super(911); } public void f1() { System.out.println("A.f1"); f2(); } public void f2() { System.out.println("A.f2"); } };

slide: Naive: BodyOfA



  class C extends A { 
C
public void f2() { System.out.println("C.f2"); } };

slide: Usage: C



    C c = new C; c.f1();    
  

slide: Example: calling C



  class BodyOfA extends A { 
BodyOfA
public BodyOfA(A h) { super(911); handle = h; } public void f1() { System.out.println("A.f1"); handle.f2(); } public void f2() { System.out.println("A.f2"); } A handle; // reference to invocation context };

slide: Handle/Body: BodyOfA



slide: Separating interface hierarchy and implementation



  class item { 
item
public item(String x) { _name = x; _self = null; } String name() { return exists()?self().name():_name; } public void redirect(item x) { _self = x; } boolean exists() { return _self != null; } public item self() { return exists()?_self.self():this; } item _self; String _name; };

slide: Item with self()



  public class go {
  
  public static void main(String[] args) {
  	item a = new item("a");
  	item b = new item("b");
  	a.redirect(b);
  	System.out.println(a.name()); 
indeed, b
} };

slide: item: go



  class actor { 
actor
public static final int Person = 0; public static final int Student = 1; public static final int Employer = 2; public static final int Final = 3; public void walk() { if (exists()) self().walk(); } public void talk() { if (exists()) self().talk(); } public void think() { if (exists()) self().think(); } public void act() { if (exists()) self().act(); } public boolean exists() { return false; } public actor self() { return this; } public void become(actor A) { } public void become(int R) { } };

slide: actor.java



  class student extends actor { 
student
public void talk() { System.out.println("OOP"); } public void think() { System.out.println("Z"); } };

  class employer extends actor { 
employer
public void talk() { System.out.println("money"); } public void act() { System.out.println("business"); } };

slide: Students and Employers



  class person extends actor { 
person
public person() { role = new actor[ Final+1 ]; for( int i = Person; i <= Final; i++ ) role[i]=this; become(Person); } public boolean exists() { return role [role] != this; } public actor self() { if ( role[ Person ] != this ) return role[ Person ].self(); else return role [role]; } public void become(actor p) { role[ Person ] = p; } public void become(int R) { if (role[ Person ] != this) self().become(R); else { _role = R; if ( role [role] == this ) { switch(_role) { case Person: break; // nothing changes case Student: role [role] = new student(); break; case Employer: role [role] = new employer(); break; case Final: role [role] = new actor(); break; default: break; // nothing happens } } } } int _role; actor role[]; };

slide: person.java



  class adult extends person {  
adult
public void talk() { System.out.println("interesting"); } };

slide: adult.java



  public class go { 
example
public static void main(String[] args) { person p = new person(); p.talk(); // empty p.become(actor.Student); p.talk(); // OOP p.become(actor.Employer); p.talk(); // money p.become(new adult()); p.talk(); // interesting p.become(actor.Student); p.talk(); // OOP p.become(p); p.talk(); // old role: employer p.become(actor.Person); p.talk(); // initial state } };

slide: go.java


Invocation context

handle/body


Problem
Inheritance breaks with handle/body
Background
Envelope/Letter, hiding implementations
Realization
Explicit invocation contact in body
Usage
sessions, events, kits, widgets, items

slide: Invocation context


Nested components

virtual self-reference


Problem
Realizing composites with single inheritance
Background
Decorators, prototypes
Realization
Smart delegation
Usage
Composite widgets, embedded logic

slide: Nested components


Actor pattern

dynamic role switching


Problem
Static type hierarchies may be too limited
Background
State transitions, self-reference
Realization
Dynamic instantiation and delegation
Usage
Web viewer, kit -- embedded logic

slide: Actor pattern