Hi Madi,<br><br>I've seen a few replies to your posting but none so far actually talk about the idea behind "is a", which it seemed to me you were looking for.<br><br>In object oriented programming, the two major kinds of relationships classes and objects might have with each other is the "is a" relationship (i.e. inheritance) and the "has a relationship" (i.e. composition).<br>
<br>By declaring class Dog to have an is-a relationship with class Mammal, you are saying that Dogs have all the properties that Mammals do (for instance, live birth of young, production of milk, hair/fur, kinship with Dan Fielding), plus they have some specific properties that only Dogs have (barking, chasing after Frisbees, being man's best friend). [You could go a bit further and state that no animal can be created _directly_ as being a Mammal; animals can only be specific types of Mammals. As such, you could consider Mammal to be an interface specification class (aka virtual class), but this is a more advanced concept that we don't really need to go into now.)<br>
<br>In English, you would read this relationship as "a dog is a mammal." In Perl, you would say:<br><br>package Dog;<br>use base qw (Mammal);<br>
<br>But really, Dogs are Canines, so you'd probably say Dog is-a Canine, and you'd pick up on being a Mammal by virtue of Canine is-a Mammal, and Mammal is-a Chordate, and Chordate is-a Animal, and Animal is-a Life. Is-a relationships often chain their way to some level of complexity.<br>
<br>package Life;<br># in Perl, implicitly uses the base class "UNIVERSAL"<br>.<br>
. # DNA, i haz it!<br>
.<br>
package Animal;<br>
use base qw (Life);<br>
.<br>
.<br>
.<br>
package Mammal;<br>
use base qw (Animal);<br>
.<br>
.<br>
.<br>
package Canine;<br>
use base qw (Mammal);<br>
.<br>
.<br>
.<br>
package Dog;<br>
use base qw (Canine);<br>
.<br>
.<br>
.<br>
1;<br><br>I've seen some talk of multiple inheritance. This is technically possible in Perl but often controversial. That would be like saying Dog is-a Canine, but Dog is-a Pet also. (Rocks occasionally are pets too, as are peeves.) In Perl this would be:<br>
<br>package Dog;<br>use base qw (Canine Pet);<br>.<br>.<br>.<br>1;<br><br>Old-school, you'd establish is-a relationships by manipulating the @ISA array.<br><br>Has-a relationships is where the thing possesses another thing. Dogs have eyes. They have tails too. They have collars and leashes. Each of these things can be had by wildly different other things (e.g. octopuses, jet airplanes, B&D fetishists) so these objects can be free-floating things that you can tack onto the side of anything else. They can have their own is-a relationship hierarchies too. There isn't a syntax in the language that specifically implements has-a relationships. You just kind of throw those into your objects.<br>
<br>package Dog;<br><br>
use base qw (Canine Pet);<br>
<br>use Eye;<br>use Tail;<br>use NaughtyNaughty;<br><br>sub new {<br> my $class = shift;<br> my $eye = Eye->new();<br>
my $tail = Tail->new();<br>
my $collar = NaughtyNaughty->new();<br>
my $self = bless { eye => $eye, tail => $tail, collar => $collar }, $class;<br> return $self;<br>
}<br><br>.<br>
.<br>
.<br>
<br>1;<br>
<br>Cheers,<br> - Richard<br><br><div class="gmail_quote">On Mon, Jul 14, 2008 at 2:53 PM, Madison Kelly <<a href="mailto:linux@alteeve.com">linux@alteeve.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br>
<br>
I am working on some docs, and noticed that a module is called via:<br>
<br>
use base qw(Net::DBus::Object);<br>
<br>
I am trying to understand the 'use base' syntax, and all I've been able to find in perldoc is in perlmodlib:<br>
<br>
base Establish IS-A relationship with base classes at compile time<br>
<br>
Can someone either explain to me what this means, or better, point me at what docs explain "IS-A relationship"s? I hate "just accepting" that something is at it is. Probably why I never get anything actually done. :)<br>
<br>
Thanks as always!<br>
<br>
Madi<br>
_______________________________________________<br>
toronto-pm mailing list<br>
<a href="mailto:toronto-pm@pm.org" target="_blank">toronto-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/toronto-pm" target="_blank">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br>
</blockquote></div><br>