composition

From: Andersen (alibandali_at_hotmail.com)
Date: 06/09/04


Date: Wed, 09 Jun 2004 19:33:01 +0200

Hi,

If I have 3 classes, A, B, C where A is a composition of B and C:

class A {
   public A(int i, String s) { ... }
}

class B {
   public A(int i, String s) { ... }
}

class C {
   public A a;
   public B b;
}

Which one of these two constructors are generally to be preferred for C:

public C(A varA, B varB);
{
   a=varA;
   b=varB;
}

or

public C(int x, int y, String i, String J)
{
        a=new A(x, i);
        b=new B(y, j);
}

Is anyone to be preferred? if so why?

regards,
Andersen



Relevant Pages