Prev | Current Page 247 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

In practice it is possible to deal with the
instance at a different level of specialization. In code this can be used to further avoid code repetition.
Continuing the CMS example, imagine that there is the need of a page in the back end that shows a
description and the status of all the contents in the repository, no matter if they are articles or blog posts.
Instead of having one list for each type of container, it is possible to have a unique list of type
BaseEntry .
(continued)
121
Chapter 5: Delving Into Object-Oriented Programming
var list = new List < BaseEntry > ();
list.add(new Article(???Article #1???, ???...???, Date.now()));
list.add(new BlogEntry(???Blog Entry #1???, ???...???));
list.add(new Article(???Article #2???, ???...???, Date.fromString(???2020-01-01???)));
for(entry in list)
trace(entry.title + ??? [??? + entry.onlineInfo + ???]???);
It is possible to easily manipulate the list using the fields provided in the BaseEntry class declaration. If
for example, it is needed to create a list with just the published entries, it is easy to apply a filter to the
original list and to obtain a reduced copy:
var filteredList = list.


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