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 ...

Get haXe 2 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.