Prev | Current Page 813 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

id = id;
this.name = name;
this.birthyear = birthyear;
}
public function getId()
{
return { id : id, name : name };
}
}
The PersonDatabase class contains the data and has two methods to retrieve them:
a listIds() method that returns an array containing the id and the name of the corresponding
person, and getById() that returns an instance of Person with all the data available about
the selected id.
import Person;
class PersonDatabase
{
private var persons : Array < Person > ;
public function new()
{
var rs = new Person(1, ???Richard Shakespeare???, 1561);
var js = new Person(2, ???John Shakespeare???, 1601);
rs.children.push(js.getId());
js.father = rs.getId();
// ... others omitted for brevity
persons = [rs, js /* add more here */];
}
public function listIds() : Array < PersonId >
{
var ids = new Array();
for(person in persons)
ids.push({ id : person.id, name : person.name});
ids.sort(function(x, y){
return if(x.name < y.name) -1 else if(x.name > y.name) 1 else 0; });
return ids;
}
public function getById(id : Int) : Null < Person >
{
for(person in persons)
if(person.


Pages:
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825