tags:

views:

54

answers:

1

I know the code below doesn't compile, and yes I might be crazy. What I'm trying to do is slip an implementation (B below) of a abstract class (A) as the super class of class (C) that also extends the abstract class. I'd also like to defer method override to the super class. Something like...

abstract class A {
  abstract Object get();
  abstract Object do();
  Object action();
}

class B extends A {
  B(B obj) {
      super(obj.getName()...)
   }
  Object get() { ... }
  Object do() { ... }
}

C<T> extends <T extends A> {
   C(<T extends A> obj) {
      super(obj)
   }

   Object do() { ... }

   Object whatever() {
      return action();
   }
}

Where...

C aC = new aC(new B());
aC.get() -> B.get()
aC.do() -> C.do()
aC.action() -> A.action()
+1  A: 

I think you want to use the delegate pattern.

class C extends A {

   private final A delegate;

   C(A obj) {
      this.delegate = obj;
   }

   Object get() { return delegate.get() }

   Object whatever() {
      return action();
   }
}
Thilo
Yep, this is what I ended up doing. Thanks.
cwall