If an instance of the BlogEntry class is passed as an
argument to the trace function, in Neko the output will be something like this:
Main.hx:7: { createdOn = > 2007-05-02 06:08:02, publishedOn = > 2007-04-20 01:00:00,
title = > My First Article, content = > My Content }
Whereas Flash 9 will output:
Main.hx:7: [object BlogEntry]
To change this behavior, it is possible to simply implement the toString() method like this:
public function toString() : String
{
return title;
}
And the result will be consistently the same for every platform.
Abstract Classes and Abstract Methods
In many OO languages exists the formal definition for abstract classes. An abstract class cannot be
instantiated by itself and must necessarily be sub - classed to be of some use.
This could be the case in your BaseEntry class in the blog example. The class is there just to provide a
common base for Article and BlogEntry and instances of BaseEntry should not really be created. To
forbid this possibility and to obtain a sort of abstract class, the access modifier of the constructor of
BaseEntry is changed to private .
Pages:
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256