I am looking for a design pattern which can replace inner class use case.
public class DrinkMaker {
private Sugar sugar;
private TeaPowder teaPowder;
private Milk milk;
List<Drinks> drinks ;
PrepareDrinks (RawItems rawItems ) {
this.sugar = prepareSugar(rawItems.sugarcane);
this.teaPowder = prepareTeapowder(rawItems.teaLeaves);
// MakeTeaInnerClass has dependency on sugar teapowder
drinks.add( MakeTeaInnerClass());
// MakeCoffeInnerClass has dependency on sugar teapowder and already created drinks
drinks.add( MakeCoffeInnerClass());
}
}
What I tried
I thought of creating concrete class for MakeCoffeInnerClass as MakeCoffe and MakeTeaInnerClass as MakeTea then use them in DrinkMaker as class level variable. Once we have thepower and sugar ready (after prepareSugar and prepareTeapowder ) let them pass to each instance of MakeCoffe and MakeTea class. like
private MakeTea teamake;
teamake.preare(sugar,teaPowder,drinks);
But this seems like not a good approach as we are simply passing data across classes. Help me to get a design pattern having good data model and less complex so I can make any logic changes with less effort.
Aucun commentaire:
Enregistrer un commentaire