I think the answer hinges critically on the type of data managed by Foo
subclasses. If the results are homogeneous, just extend SwingWorker
and instantiate concrete subclasses accordingly:
class Whatever {}
abstract class AbstractFoo extends SwingWorker<List<Whatever>, Whatever> {}
class Foo1 extends AbstractFoo {
@Override
protected List<Whatever> doInBackground() throws Exception {
...
}
}
If each manages a different type, make the parent generic and instantiate each concrete subclass with the required type:
class Whatever {}
class Whichever {}
abstract class GenericAbstractFoo<T, V> extends SwingWorker<T, V> {}
class Foo2 extends GenericAbstractFoo<List<Whatever>, Whatever> {
@Override
protected List<Whatever> doInBackground() throws Exception {
...
}
}
class Foo3 extends GenericAbstractFoo<List<Whichever>, Whichever> {
@Override
protected List<Whichever> doInBackground() throws Exception {
...
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…