in reply to Re^2: Private attributes in Perl 6 objects
in thread Private attributes in Perl 6 objects
All "BUILD" methods in the inheritance chain will be called, so subclasses need not know about parents:
class Dot { has $.x; has $.y; has $!z; submethod BUILD(:$!x, :$!y, :$!z) { say "Initializing!"; } method get { return ($!x, $!y, $!z); } method getz { return $!z; } } class Dot2 is Dot { has $!w; submethod BUILD(:$!w) { say "Initializing 2!"; } method get { # No access to $!z here of course (it is private) # Also note use of public $.x, $.y not private $!x, $!y return ($.x, $.y, $!w); } } my $a = Dot2.new(x => 23, y => 42, z => 2, w => 12); say $a.get; say $a.getz;
Good Day,
Dean
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Private attributes in Perl 6 objects
by Anonymous Monk on Nov 03, 2015 at 09:17 UTC |