SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public Interface IPizza {
  2.     public int cost();
  3. }
  4.  
  5. public abstract class AbstractPizzaDecorator implements IPizza {
  6.     private IPizza pizza;
  7.     public AbstractPizzaDecorator (IPizza p) {
  8.         if(p == null)
  9.             throw new Exception();
  10.         pizza = p;
  11.     }
  12.     public abstract int condimentCost();
  13.     //posso rendere il metodo concreto in caso esempio avessi
  14.     //tanti condimenti allo stesso prezzo, per averlo generale
  15.     //e farlo ereditare sotto evitando di scrivere la stessa roba
  16.     public int cost(){
  17.         return pizza.cost() + condimentCost();
  18.     }
  19. }
  20.  
  21. public class ConcretePizzaDecorator extends AbstractPizzaDecorator {
  22.     public ConcretePizzaDecorator (IPizza p) {
  23.         super(p);
  24.     }
  25.     public int condimentCost() {
  26.         return 300;
  27.     }
  28. }
  29.  
  30. public class ConcretePizza implements IPizza {
  31.     public int cost() {
  32.         return 500;
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top