Prev | Current Page 248 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

filter(function(entry)
{
return entry.isOnline();
});
Note that in the passed function you do not have to mandatorily declare the type of the argument entry
because the compiler can infer it from the usage context.
Using Interfaces
An interface is a type that is completely abstract; it provides the skeleton (instance field definitions) but
no implementation at all. Because it does not provide any routine, it cannot be instantiated. For this
reason classes can only implement interfaces and not extend them. A class implementing an interface must
mandatorily provide a definition for each field contained in the interface.
The interface declaration is very similar to the class declaration and uses the same naming constraints;
see Figure 5 - 6 for its syntax.
interface Name implements Interface, implements Other
{
//...
}
multiple implemented interfaces are
separated using commas
Figure 5-6
The interface body can contain function and variable definitions as it happens for the class definitions
with a notable difference: Function cannot have a body as shown in the following example.


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