Again i am going to argue not really. An interface describes the method
signatures, but not the signatures of the constructors, so an interface
does
not limit the set of allowable constructors. The generic class only
knows that
the type is a class, implements a specific interface and has a specific
set of
constructors. In the sample I posted the only supported constructor is
the no
arg constructor. The generic class does not know the details of all
concrete
classes present and _future_ of type T1 or T2 and therefore it cannot
know all
possible parameterized constructors of _future_ concrete classes of type
T1
or T2. Remember, the idea of using generics to simulate multiple
inheritance
of implementation is to support plugging in _new_ concrete classes with
new
implementations in the future without changing the calling code. These
new
classes may have new constructors with a different set of parameters
than
those present at the time of the writing of the generic class.
The interfaced based class has no such limitation as you can create a
new
class as in new Foo(new T1Implementatio n(p1,p2));
One possible solution is a generic constructor of form Foo(object[]
arrayParameters ), but this is not type safe.
Regards,
Jeff
So, following that same logic, you should also know the exact
signatures of
each constructor, thus you can list all necesary parameters (with their
correct types) in the GenericClass ctor<
*** Sent via Developersdex
http://www.developersdex.com ***