Skip to content

Commit

Permalink
Added a section on single inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Follett committed Aug 30, 2010
1 parent 917d907 commit 1512265
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/classes-and-objects.pod
Expand Up @@ -348,6 +348,41 @@ the various other dependencies in order, giving the output:
making dinner
eating dinner. NOM!

=head1 Inheriting the Farm

Object Oriented Programming provides the concept of inheritance as one of the
mechanisms to allow for code reuse. Perl 6 supports the ability for one class
to inherit from multiple classes. When a class inherits from another class it
acquires all of the attributes and methods of the base class.

=begin programlisting

class Farmer
{
has $.farm is ro;

method plant_crops( Str $crop )
{
"Planting some $crop at the farm"
}
}

class FarmerKid is Farmer
{
}

=end programlisting

Now all the objects of type FarmerKid will inherit the base class' farm
attribute and plant_crops method as though they were declared on FarmerKid.

=begin programListing

my $fk = new FarmerKid( farm => 'across from the dairy');

$fk.plant_crops('wheat');


=head1 Exercises

B<1.> The method C<add-dependency> in C<Task> permits the creation of I<cycles>
Expand Down

0 comments on commit 1512265

Please sign in to comment.