/** * 根据type来选择策略模式, * 入参和出参必须是有要求。 */ public User getUserByType(Long type, Long a, Long b){ return MAP.get(type).apply(a, b); }
/** * spring中,可以此方法中 使用外部类中定义的IOC容器中的bean */ public User getSimpleUser(Long a, Long b){ User user = new User(); user.setName("simple user" + a + b); return user; } public User getUser(Long a, Long b){ User user = new User(); user.setName("user" + a + b); return user; } public User getComplexUser(Long a, Long b){ User user = new User(); user.setName("complex user" + a + b); return user; } }
This is copyright.