O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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?

Now, we have two methods 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required