spring如何优雅处理策略模式if类型判断
@Service public class B1Impl implements InterfaceB { //通过map key放类型,值放抽象类型,每次就不用if判断了 Map<String, InterfaceA> interfaceAMap = new HashMap<>(); //spring 会自动注入interfaceA的所有实现 @Bean("testB1Impl") public Map<String, InterfaceA> B1Impl(List<InterfaceA> interfaceA) { if(CollectionUtils.isEmpty(interfaceA)) { return null; } for(InterfaceA a : interfaceA){ interfaceAMap.put(a.getType(),a); } return interfaceAMap; } @Override public Map<String, InterfaceA> getInterfaceAMap() { return interfaceAMap; } }