那里存在interface Algorithm
存在class MathAlgorythm implements Algorithm
(returns MathResult, which implements Result
)
存在class ChemitryAlgorythm implements Algorithm
(returns ChemitryResult, which implements Result
)
此外,还有一个Context class
,用于将数据传递给这些算法。数据通过以下方式传递:
public Result executeStrategy(Data data) {
return algo.execute(data);
}
假设我,executeStrategy 并回来
return MathAlgorithm.execute(data);
我得到了 Result 类型的东西,对吗?
然后我再次执行
return ChemitryAlgorithm.execute(data);
我得到一些结果
问题: 结果是一个接口。我需要访问作为 MathResult 或 ChemistryResult 的具体类实现。换句话说。一旦我得到结果类型的东西,我需要更深入地挖掘并知道隐藏在接口后面的类
我希望这种漫谈不会太混乱。
感谢您阅读和回复