"Making" an object in a constructor #2

  • Follow


I have the following situation:
Class A implements AI
Class B has a method public AI x();
I want to extend A (or implement an extension of AI) to get Class C
with a constructor such that the instantiation constructed equals (new
B()).x().
This won't be circular, as B does not use this constructor to get its
A.

I've done something close by creating Class C {
private AI a;
C {a = new B().x();}
public A getA () {return a;}
}

I was looking for a solution that doesn't require the psuedoproperty
getA.  I could also make a public and do new C().a.  Still not quite
(A)(new C()).

Any ideas how I can make this work?

Ken
0
Reply ken4434 (3) 7/2/2004 8:27:13 PM

Ken K <ken@kenkast.com> wrote:
> I have the following situation:
> Class A implements AI
> Class B has a method public AI x();
> I want to extend A (or implement an extension of AI) to get Class C
> with a constructor such that the instantiation constructed equals (new
> B()).x().
> This won't be circular, as B does not use this constructor to get its
> A.

As I understand this, you want a class C that extends A or implements AI,
which augments the object returned by (new B().x()).


> I've done something close by creating Class C {
> private AI a;
> C {a = new B().x();}
> public A getA () {return a;}
> }

First, you omitted the brackets for the constructor.
Second, you're defenitely on the right track with the instance variable.

Note however, that class C extends A or implements AI. You can thus
augment the object C.a by declaring all methods of A or AI and
redirecting the calls to the same methods on C.a.

Of course, you'll add/change methods where required, or you wouldn't need
class C and use the object (new B().x()) directly...



-- 
Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2
0
Reply oscar1 (318) 7/2/2004 9:23:56 PM


1 Replies
22 Views

(page loaded in 0.072 seconds)


Reply: