Controller receives a List of several Fruits from user. Controller needs to make juice from each of these fruits. One Juicer can make juice out of orange and grapefruit; another Juicer knows to make juice from apple, banana and papaya; and so on. Every Juicer can accept multiple Fruits in one go, it will process only the Fruits it's capable of and ignore other Fruits untouched. Kindly suggest an appropriate design for this problem. I have been considering the following options:
- Controller calls
MasterJuicer.juice(List<Fruit> fruits)
.MasterJuicer
in turn callsCitrusJuicer.juice(fruits)
andPulpyJuicer.juice(fruits)
. - Chain of Responsibility does not seem right. Order in which Juicers are called does not matter.
- Factory? Controller calls
JuicerFactory.getJuicers(List<Fruit> fruits)
to get aList<Juicer>
. Controller then loops thru each Juicer and callsJuicer.juice(fruits)
. Is it common for a Factory to return a List of instances? - Maintain a registry of Fruit vs. Juicer in a
Map
? Controller callsFruitsRegistry.getJuicer(Fruit fruit)
for each fruit, then calls each Juicer in a loop.