创建助手以根据输入选择特定的地图

时间:2017-03-29 07:35:55

标签: java collections

我不确定如何针对以下问题进行最佳设计

Map<String, Person> dataSource1_Map1 = {fill this map up from data source1}
Map<String, Student> dataSource1_Map2 = {fill this map up from data source1}
Map<String, Person> dataSource2_Map1 = {fill this map up from data source2}
Map<String, Student> dataSource2_Map2 = {fill this map up from data source2}

(地图位于一个其对象随处可访问的类中)

我需要这些地图的代码不需要知道填充地图的数据源。

我正在思考

//DataMaps contains two maps - Map<String,Person> & Map<String,Student>
DataMaps maps = DataSourceHelper.getMaps(values that help determine source)
doStuff(maps);

getMaps(input values)
{
  if(values -> data source1)
  return data source1 maps
  else
  return data source2 maps
}

我不确定如何最好地设计DataMaps&amp; amp; DataSourceHelper或者是否有更好的方法来解决这个问题。

0 个答案:

没有答案