Prev | Current Page 276 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

hx
Point.hx
// ...
style
Color.hx
FillKind.hx
// ...
Main.hx
GeomImport.hx
// ...
Declaring a Package
The package statement must be the first in a file; any subsequent declaration will be automatically
associated to it. A package is declared like this:
package name.subname;
Where name is the main package and subname is a nested package. The number of nesting levels is left
to the programmers and his or her style of organizing the code.
141
Chapter 6: Organizing Your Code
The geom package contains a Point.hx file that declares the Point class, as in the following code:
// content of file geom/Point.hx
package geom;
class Point
{
public var x : Float;
public var y : Float;
public function new (x : Float, y : Float)
{
this.x = x;
this.y = y;
}
}
The complete name of the class Point is geom.Point while its name in the package is simply Point . The
first line indicating the current package is mandatory and cannot be omitted.
In this example and others in this chapter, classes are used in the examples, but in some circumstances
and varying from project to project, other structures like typedef or enum may constitute better
alternatives.


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