Therefore, now our fridge will only be able to access eatable items.
First, create a parameterized
Fridge
class that will only accept types implementing theEatable
interface :class Fridge<T: Eatable)> { public function new() {} }
In this class, we will create two methods: an
add
and aremove
method and we will use anArray
to store the list of what is inside ourFridge
:class Fridge<T: Eatable)> { private var items : Array<T>;public function new() { items = new Array<T>(); //Initialize the Array } public function add(item : T) { array.push(item); } public function remove(item : T) { array.remove(item); } }
For sure, in this state, our fridge is basically just a wrapper around the array class, but now we will do something interesting with it.
We will define the
Eatable
interface, so that we can store the date before which the eatable should be eaten, as follows:interface...