mardi 16 mars 2021

Bridge pattern use and structural design patterns

I have a project where I am asked to include at least one structural design pattern, and I chose the a desktop app for food delivery, my thoughts where that I have an abstract class FoodElement that derives VeganFoodElement and a NormalFoodElement. Now for each category I can either choose a dish or a drink, can I separate them this way?

public abstract class FoodElement {

     private String elementName;
     private float elementPrice;

     public abstract void showFoodElement();
     public abstract float getPrice();

}

public class NormalFoodElement extends FoodElement{

    private TypeElementRepas elementNormal;

    @Override
    public void afficherElementRepas() {}

    @Override
    public float getPrix() {}
}

public interface TypeFoodElement {

    void showAttributes();
}

public class Drink implements TypeFoodElement {

    private int sugarQuantity=0;

    @Override
    public void showAttributes() {}

    @Override
    public void addSugar() {
       this.sugarQuantity += 1;
    }

}

public class Dish implements TypeFoodElement {

    @Override
    public void showAttributes() { }

}




Aucun commentaire:

Enregistrer un commentaire