3 ms·
Hmm... how about... @Service public class SandwichFactoryImpl implements SandwichFactory { @Autowired public EmptySandwichFactory emptySandwichFact
by astral303 13y ago
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);
}
}
- FuzzyDunlop 13y agoThis is much more inspired. I sort of feel sympathetic, because of the potential mental anguish you were likely to have incurred while writing it.