Prev | Current Page 238 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Every class can possibly extend no more than one parent. This is a quite common paradigm in
OOP known as single inheritance ; haXe also provides alternative ways to extend as explained later in
this chapter.
An extended class inherits all the private and public instance fields but not the static ones. For people
coming from other OO languages like C# the private access modifier is equivalent to the protected
modifier.
Going ahead with the CMS example, a new article class is implemented. It has really a lot in common
with the BlogEntry class. They both have a title, a content, an excerpt and of course a way to be
published. So what? Must the code be repeated twice? Of course not. A common base is what is needed.
This is when inheritance comes into play.
Two new classes are then created: Article and BaseEntry . All the code written so far for the
BlogEntry class is moved to the BaseEntry . Article and BlogEntry are set to extend BaseEntry and
will inherit all its fields with no repetitions at all.
class BaseEntry
{
public var title(default,default) : String;
public var content(default,default) : String;
public var createdOn(default,null) : Date;
public var onlineInfo(getOnlineInfo,null) : String;
public var excerpt(getExcerpt, setExcerpt) : String;
private var definedExcerpt : String;
private var publishedOn : Date;
public function new (title : String, content : String)
(continued)
116
Part I: The Core Language
{
this.


Pages:
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250