class Employee { has Str $.name is readonly is required; # "readonly" is the default. has Str $.title is rw is required; method name_and_title { my $name = self.name; my $title = self.title; return "$name, $title"; } } class Employee::Former is Employee { method name_and_title { my $old = callsame; return "$old (Former)"; } # Slide #85. # The + says "we're overriding the definition in our superclass. Everything stays the same # except for the provided changes." # Here, we give a default. If no value is given, the default is used, which lets us satisfy the # "required" even when no value was given in the call to the constructor. # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX # Is there not a Raku counterpart for this? # has '+title' => ( # default => 'Team Member', # ); # My poor attempt: has $.title is default('Team Member'); # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX } # Commented out. use Employee; my $peon = Employee.new( name => 'William Toady', title => 'Associate Assistant', ); say $peon.name_and_title; # Get name_and_title. # Commented out. use Employee::Former; my $ex_peon = Employee::Former.new( name => 'William Toady', title => 'Associate Assistant', ); say $ex_peon.name_and_title; # Get name_and_title. # Where is the test code? Answer: Slide #87. # Name this script mip-087-001.raku my $ex_peon2 = Employee::Former.new( name => 'William Toady', ); say $ex_peon2.name_and_title; # ===> William Toady, Team Member (former)