E
EdwardH
I have two classes, Manager and Data. I use them as follows...
Class Manager
{
private Vector<Data1> dataVector;
add()
{
dataVector.add( new Data1(blabla) );
}
}
What I want to do is use the same Manager class use several Data-typed
classes, Data1, Data2 and Data3. They all have the same Interface but
work differently.
Unfortunately Manager doesn't want to work with Interfaces
(DataInterface, for example) because of the "new".
Does anyone have any suggestions as to how to make Manager more flexible?
Will I, as I have feared, have to make a subclass (extends) of Manager
to handle each type of Data?
PS: I've tried using generics ...
Class Manager<DataType>
private Vector<DataType> dataVector;
...
dataVector.add( new DataType(blabla) );
but once again Java doesn't know how to instanciate DataType. Interfaces
don't have constructors, it says.
Class Manager
{
private Vector<Data1> dataVector;
add()
{
dataVector.add( new Data1(blabla) );
}
}
What I want to do is use the same Manager class use several Data-typed
classes, Data1, Data2 and Data3. They all have the same Interface but
work differently.
Unfortunately Manager doesn't want to work with Interfaces
(DataInterface, for example) because of the "new".
Does anyone have any suggestions as to how to make Manager more flexible?
Will I, as I have feared, have to make a subclass (extends) of Manager
to handle each type of Data?
PS: I've tried using generics ...
Class Manager<DataType>
private Vector<DataType> dataVector;
...
dataVector.add( new DataType(blabla) );
but once again Java doesn't know how to instanciate DataType. Interfaces
don't have constructors, it says.