The decorator pattern is useful to give an existing object additional features.
So e.g. there is a main dish which can have several side dishes. The side dishes would be the decorators. All dished would inherit from the same base class dish . So far so good. That is called decorator pattern in a simplified way.
But the calls will be very complex. Dish dish = new Salad(new Icecream (new mainDish()));
So what is wrong about this design.
Every main dish has a member called ArrayList<Dish> lstSideDishes ;
So now every main dish can just add there side dishes and process them.
What do you think. Thanks.
Aucun commentaire:
Enregistrer un commentaire