Prev | Current Page 242 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


118
Part I: The Core Language
class Article extends BaseEntry
{
public function publishOn(date : Date) : Void
{
publishedOn = date;
}
private override function getOnlineInfo() : String
{
return if(publishedOn != null & &
publishedOn.getTime() > Date.now().getTime())
???Not yet on-line, scheduled for ??? +
DateTools.format(publishedOn, ???%Y-%m-%d???);
else
super.getOnlineInfo();
}
}
Inside a redefined function, if you want to call the overridden definition it is necessary to use the
super identifier.
The method getOnlineInfo() has been redefined to accommodate the extra functionality introduced.
In the true part of the if statement, a new case for a future planned publication date has been introduced
while the false condition recalls the original function as defined in the BaseEntry class.
Having multiple classes that share the same function definitions with different implementations is
known in OOP as polymorphism .
Constructor Override
The use of the super identifier in a constructor is slightly different from what you have already seen for
invoking functions in a parent class.


Pages:
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254