[aspectc-user] Base class substitution

Francisco Afonso afonsofc at hotmail.com
Mon Apr 2 10:46:45 CEST 2007


Hi,

I have tried to do it in AspectJ, and it works.
This is my example code.

--------------------------------------------
public class Base {
  void operation(){
    System.out.println("base");
  }
}

public class Derived extends Base {
}

public class Base2 extends Base{
  void operation(){
     System.out.println("base2");
  }
}

public class Test {

  public static void main(String[] args) {

       Base bb1 = new Base();
       bb1.operation();

       Base bb2 = new Derived();
       bb2.operation();
  }
}

public aspect Intro {
   declare parents: Derived  extends Base2;
}

Program output:
base
base2

----------------------------------------------

As in Java there is no multiple inheritance, a "declare parent" for a 
derived class will replace the old base class.
But this is allowed only if the new base class derives from the old one, 
otherwise the following message is displayed:
"can only insert a class into hierarchy, but ____ is not a subtype of ____".

I think that it would be nice if in AspectC++ we could define if an 
introduction of a base class would be implemented by addiction or 
substitution.

Francisco Afonso

_________________________________________________________________
Live Search Maps – find all the local information you need, right when you 
need it. http://maps.live.com/?icid=hmtag2&FORM=MGAC01




More information about the aspectc-user mailing list