Prev | Current Page 217 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

A static field belongs to the class
itself and is always accessible; an instance field is specific to an object and depends on its existence.
As an example, the implementation of a blog entry class in a hypothetical CMS (content management
system) application is provided.
class Main
{
static function main()
{
var entry : BlogEntry = new BlogEntry();
entry.title = ???My First Blog Entry???;
entry.content = ???Lorem ipsum ...???;
trace(entry.title);
}
}
class BlogEntry
{
public var title : String;
public var content : String;
public function new () { }
}
Two classes are defined; Main is just an entry point to test the execution of the code, while BlogEntry is
part of the CMS business logic. BlogEntry just defines a data container for a bunch of information: the
declaration of two variables, title and content , and a method new with an empty implementation.
Fields access, as shown in the main function, is performed using the classic dot - syntax as in many other
languages like C/C++/C# and Java.


Pages:
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229