我有一个主类 - 模拟器 - 使用另外两个类 - Producer和Evaluator.生产者生成结果,而评估者评估这些结果.模拟器通过查询生产者然后将结果传送给评估者来控制执行流程.
Producer和Evaluator的实际实现在运行时是已知的,在编译时我只知道它们的接口.下面我粘贴接口,示例实现和Simulator类的内容.
package com.test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
* Producers produce results. I do not care what is their type, but the values
* in the map have to be comparable amongst themselves.
*/
interface IProducer {
public Map<Integer, Comparable> getResults();
}
/**
* This implementation ranks items in the map by using Strings.
*/
class ProducerA implements IProducer {
@Override
public Map<Integer, …Run Code Online (Sandbox Code Playgroud)