Prev | Current Page 277 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Implicit Import
The main types ??” their name matches the name of the file with .hx extension ??” can be referenced
implicitly. It is possible to recur to a main type simply by using its complete name or the relative one if it
is used in the same package.
The Circle class uses the Point class to define a variable that stores the center point of circle:
// content of file geom/Circle.hx
package geom;
class Circle
{
public var center : Point;
public var radius : Float;
public function new(center : Point, radius : Float)
{
this.center = center;
this.radius = radius;
}
public function perimeter()
{
return( 2 * Math.PI * radius );
}
}
Note that the Point class is used in this file without the geom package prefix and without any import
declaration. The Point class is automatically discovered and immediately accessible, because it is in the
same package as Circle . Point could also be referenced using its complete name, like this:
public var center : geom.Point;
142
Part I: The Core Language
While using the complete name is optional when working in the same package, it becomes mandatory
when referencing a type in a different package or in a sub - package.


Pages:
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289