拥有这个设计:
这是一个好的设计吗?
interface Foo<T> {
void doSomething(T t);
}
class FooImpl implements Foo<Integer> {
//code...
}
interface Bar extends Foo {
//code...
}
class BarImpl extends FooImpl implements Bar {
//code...
}
我遇到了编译错误:
接口Foo不能以不同的参数实现多次: Foo和Foo
这个问题的简单解决方法是:
interface Bar extends Foo<Integer> {
// code...
}
Bar接口中的整数类型完全没有用处。
有没有更好的方法来解决这个问题?有没有更好的设计?
感谢您的建议。
编辑:
给出的解决方案:
> interface Bar<T> extends Foo<T>
可以,但这与我的先前解决方案相同。我不需要Bar中的T类型。
让我举个更好的例子:
interface ReadOnlyEntity {
}
interface ReadWriteEntity extends ReadOnlyEntity {
}
interface ReadOnlyDAO<T extends ReadOnlyEntity> {
}
interface ReadWriteDAO<K extends ReadWriteEntity, T extends ReadonlyEntity> extends ReadOnlyDAO<T> {
}
这是一个好的设计吗?