Our main function

Now we will create a simple main function in order to test whether everything works as expected.

In this function, we will create our Fridge, create two items, and add them in the fridge. Then we will iterate over our fridge:

class FridgeManager
{
   private static var fridge : fridgeManager.Fridge;
   
   public static function main(): Void
   {
      fridge = new fridgeManager.Fridge();
      
      var myDrink = new fridgeManager.Drink();
      myDrink.name = "Benjamin's drink";
      
      var myFood = new fridgeManager.Food();
      myFood.name = "Benjamin's food";
      
      fridge.addItem(myDrink);
      fridge.addItem(myFood);
      
      //Let's display what's inside the fridge:
      for(stored in fridge)
      {
         trace(stored.name);
      }
   }
}

Pop quiz – Typedef, interfaces, and Enums

  1. Is it possible for the compiler to ...

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.