Time for action – Writing our Fridge class
Now, let's start writing our Fridge
class.
Let's start of easily by just implementing it so that it has a list of storables in which to store our items:
package fridgeManager; class Fridge { public var storedItems : List<Storable>; public function new() { storedItems = new List<Storable>(); } public function addItem(item : Storable) { storedItems.push(item); item.storedOn = Date.now(); } public function removeItem(item : Storable) { storedItems.remove(item); item.storedOn = null; } }
What just happened?
to manage items in the fridge: addItem
and removeItem
.
The addItem
function will add the item to the list and update its storedOn
property. The removeItem
function will set storedOn
to null as the object ...
Get haXe 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.