[otj-users] Problem with inner class

Andreas Werner andreas at wernerx.de
Wed Mar 21 21:54:54 CET 2007


Hi,

I have a question regarding inner classes...

Scenario:
I want to replace a method of a class C, thus I created a role which
implements a callin method.
So far all is fine.
But in this method there has to be instantiated a class D, which is an
inner (not static) class of C! My solution for this issue was to
decapsulate class D by another role inside the same team.

The concrete problem is, that if I want to call the base constructor via
base(...), OTDT shows up an error marker:
"No enclosing instance of type C is accessible. Must qualify the
allocation with an enclosing instance of type C (e.g. x.new A() where x
is an instance of C)."

Here is a snippet of the team class:
public team class T {

  public class RoleA playedBy C {

    callin void methodXY(){
      // some code
      new RoleB(...);
      // some code
    }
    methodXY <- replace methodXY;
  }

  public class RoleB playedBy D {
    public RoleB(...) {
      base(...);  // *error marker*
    }
  }
}

My workaround:
I made the inner class D static and everything is fine...

But usually you cannot edit the adapted piece of software!
Is there another way to achieve this or have I missed something?

Thanks, Andreas



More information about the otj-users mailing list