Prev | Current Page 245 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


private function new (title : String, content : String)
Now trying to instantiate the BaseEntry class throws an error at compile time.
Sometimes it is useful to have the abstract concept applied to methods. In this case the base class just
declares the function signature and delegates the actual implementation to its descendants. To enforce
this type of constraint the base class defines a function that always throws an error; if this function is not
overridden in its descendants, the code execution will be blocked by the thrown error.
class Animal
{
public function speak() : String
{
throw ???abstract method, provide an implementation in the sub-class???;
(continued)
120
Part I: The Core Language
return null;
}
}
class Dog extends Animal
{
public function new() { }
public override function speak() : String
{
return ???bark!???;
}
}
class Cat extends Animal
{
public function new() { }
public override function speak() : String
{
return ???meow!???;
}
}
Error handling is discussed in detail in Chapter 7 ; for now, it is enough to know that throw just creates
an error in the code flow.


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