Applying a data factory pattern
In this section, we will apply a factory pattern to create objects of type cheese. This will in turn implement a filling interface. Each object will consist of several properties such as price and calorific value. Some of these values will be presented in our list items and others will be available only through an expanded view or accessible only via code.
One of the few disadvantages of design patterns is the large number of classes that soon accumulate. For this reason, before beginning the following exercise, create a new package inside the java
directory, called fillings
.
Follow these steps to generate our cheese factory:
Create a new interface called
Filling
in thefillings
package and complete it like so:public interface Filling { String getName(); int getImage(); int getKcal(); boolean isVeg(); int getPrice(); }
Next, create an abstract class that implements
Filling
, calledCheese...