Prev | Current Page 243 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

First of all to call the constructor of a super class the super
identifier is used directly as a function; then the constructor signature can be completely different from
parent to child. That means that a base class that has a constructor with no arguments can be redefined
in a subclass using one or more arguments or that a private constructor can be changed in a public
constructor.
The use of the modifier override is not allowed in the declaration of the constructor.
The Article class from the previous example can be modified to take advantage of a redefined
constructor:
public function new (title : String, content : String, ?date : Date)
{
super(title, content);
if(date != null)
publishOn(date);
}
119
Chapter 5: Delving Into Object-Oriented Programming
toString()
Every value in haXe, whatever its type, can be automatically converted into a string when required. The
result of the conversion depends on the type of the value and on the platform in which the conversion is
executed. For primitive types such as floats or integers , the result obtained is always consistent, but in the
case of class instances the result may vary greatly.


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