Jon*_*ny5 2 java polymorphism inheritance frameworks overloading
我的问题如下:
我们有一个内部工作的算法
这将成为Java中的框架.要解决一个真正的问题,需要给出一个Expression和一个Manipulator的特定实现,而Algorithm类将完成剩下的工作.
假设我们需要针对特定问题的ProblemExpression和ProblemManipulator.
ProblemExpression可能包含许多新字段,可由ProblemManipulator使用.
现在,我只能想到两种编写干净代码的方法:
但我觉得这不是我应该怎么做的.还有其他建议吗?
关心并提前感谢您,
Xaero.
听起来你应该使用Generic.喜欢
interface Manipulator<E extends Expression> {
public void manipulate(E expression);
}
class ProblemManipulator implements Manipulator<ProblemExpression> {
public void manipulate(ProblemExpression expression) {
// expression is a ProblemExpression
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
241 次 |
最近记录: |