Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Private attributes in Perl 6 objects

by duelafn (Parson)
on Nov 02, 2015 at 23:11 UTC ( [id://1146776]=note: print w/replies, xml ) Need Help??


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
    Thank you very much, Dean, for this additional information.

    Have a nice day.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1146776]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-26 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found