First page Back Continue Last page Overview Graphics
Perl 6: OOP
class Point {
has Num $.x is rw;
has Num $.y is rw;
method clear() { $.x = 0; $y .= 0; }
}
my $pt = Point.new( x => 2.0, y => 3.0 );
$pt.x = 5.0;
print $pt.y;
$pt.clear();
Notes:
Veniamo agli oggetti: la dichiarazione di classi è molto più pulita ed esplicita (class, has, method)