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—Representing different types of articles

Now, imagine that the company you work for wants a blog with different types of articles— text-based articles and image-based articles. What they want is simple: a text-based article that is made of a String, and an image-based article that stores the URL of the image. All types of articles need to have a title.

At first, let's write the Article class. This one will define what all articles have.

class Article
{
public var title : String;
}

Notice that we did not create a constructor for this class: an article has to be either text-based or image-based in this example, being able to construct an instance of the Article class would be nonsense.

We want text-based and image-based articles to ...

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