Comment Comment by astral303 Hmm... how about...@Service public class SandwichFactoryImpl implements SandwichFactory { @Autowired public EmptySandwichFactory emptySandwichFactory; @Autowired public FoodComponentFactoryFactory foodComponentFactoryFactory; @Override public Sandwich makeSandwich(Collection<FoodComponentDescription> foodComponentDescriptions) { Sandwich sandwich = emptySandwichFactory.newSandwich(); for (FoodComponentDescription foodComponentDescription : foodComponentDescriptions) { FoodComponentFactory foodFactory = foodComponentFactoryFactory.getFactory(foodComponentDescription.getType()); for (int i = 0; i < foodComponentDescription.getQuantity(); i++) { sandwich.addFood(foodFactory.create()); } } return sandwich; } public SandwichDTO makeMyFavoriteSandwich() { Collection<FoodComponentDescription> components = Lists.newArrayList(); components.add(new FoodComponentDescription(FoodType.BREAD, 1)); components.add(new FoodComponentDescription(FoodType.BACON, 2)); components.add(new FoodComponentDescription(FoodType.BREAD, 1)); return makeSandwich(components); } } parent astral303 13 years ago
@Service public class SandwichFactoryImpl implements SandwichFactory {