samedi 6 février 2016

Java: Decorator Design Pattern Multiple Decorators

sorry I haven't coded yet since I don't like coding something that I'm not so sure of. I just recently learned that there are design patterns in oop and it has been written by the GoF.

So here's the problem: I have these classes in mind:

  1. public abstract class Pizza has public abstract methods: String getDescription(), Double Cost()
  2. public abstract class PizzaDIY extends Pizza has public abstract methods: String getDescription(){return "DIY"}, Double Cost(){return 150.50}
  3. public abstract class PizzaToppingDecorator extends Pizza has public abstract methods: String getDescription(), Double Cost()
  4. public abstract class PizzaSizeDecorator extends Pizza has public abstract methods: String getDescription(), Double Cost()
  5. public abstract class PizzaCrustDecorator extends Pizza has public abstract methods: String getDescription(), Double Cost()
  6. public class Pepperoni extends PizzaToppingDecorator has private attribute: Pizza pizza; public methods: Pepperoni(Pizza pizza){this.pizza = pizza},String getDescription(){return pizza.getDescription() + " Pepperoni"}, Double Cost(){return pizza.cost() + 12.60}
  7. and so on...

so my question with this design is the fact that is it okay to have more than one (1) decorator? if no, what other design pattern is best used for this?

Aucun commentaire:

Enregistrer un commentaire