我有索引项目的要求。此服务应运行同步或异步。索引服务设计 - 同步/异步
我开始设计一个接口
public interface IndexService{
public void index();
}
和两个实现,一个是异步指数:
public class AsyncIndex implements IndexService {
public void index(){
//... Creates a Thread and index the items
}
}
而另外一个同步指标
public class SyncIndex implements IndexService {
public void index(){
//... Creates a Thread and index the items
}
}
但现在还有另一种具有IndexService的设计,它有一个作为异步服务或as执行的标志一个同步服务:
public interface IndexService{
public void index(int mode);
}
所以现在的实现将知道如何运行基于该标志。
我知道第一个设计更好,但我需要利弊来解释原因。