On Thu, Dec 10, 2009 at 10:41 AM, Madison Kelly <span dir="ltr">&lt;<a href="mailto:linux@alteeve.com">linux@alteeve.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Anywho, I&#39;ve been re-reading the (sparse) Net::DBus docs and it always shows it&#39;s constructor using the &quot;super&quot; method. I know that this has to do with inheritance, but to be honest, I&#39;ve never really understood the true meaning of this.<br>
</blockquote><div><br>hi madison,<br><br>perhaps this will help you understand a bit more about what SUPER does, and how inheritance works in perl.<br><br>####[ START Foo.pm ]###<br><font face="courier new,monospace">{ package Foo;<br>
    sub new { bless {}, shift }<br>    sub says { print shift()-&gt;word, &quot;\n&quot; }<br>    sub word { &#39;foo!&#39; }<br>1 }<br>{ package Foo::Bar;<br>    use base qw(Foo);<br>    sub word { &#39;bar!&#39; }<br>1 }<br>
{ package Foo::Bar::Baz;<br>    use base qw(Foo::Bar);<br>    sub says {<br>        my $self = shift;<br>        print __PACKAGE__, &quot; isa Foo\n&quot; if $self-&gt;isa(&#39;Foo&#39;);<br>        print &#39;Foo::Bar says &#39;, $self-&gt;SUPER::word, &quot;\n&quot;,<br>
            __PACKAGE__, &#39; says &#39;, $self-&gt;word, &quot;\n&quot;;<br>    }<br>    sub word { &#39;baz!&#39; }<br>1 }</font><br>####[ END Foo.pm ]###<br><br><span style="font-family: courier new,monospace;"><span style="color: rgb(255, 0, 0);">bash$</span> perl -MFoo -e &#39;Foo-&gt;new-&gt;says&#39;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">foo!</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"><span style="color: rgb(255, 0, 0);">bash$</span> perl -MFoo -e &#39;Foo::Bar-&gt;new-&gt;says&#39;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">bar!</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"><span style="color: rgb(255, 0, 0);">bash$</span> perl -MFoo -e &#39;Foo::Bar::Baz-&gt;new-&gt;says&#39;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Foo::Bar::Baz isa Foo</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Foo::Bar says bar!</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Foo::Bar::Baz says baz!</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace; color: rgb(255, 0, 0);">bash$ </span><br style="font-family: courier new,monospace;">
<br>as a general rule though, it&#39;s best to avoid &quot;implementation inheritance&quot; (&quot;use base&quot;, &quot;push @ISA&quot;, &quot;use parent&quot;) as much as humanly possible. if at all possible it&#39;s much better in practice to use &quot;interface inheritance&quot; [&quot;use Module qw( some interfaces to import )&quot;]. inheritance is intrinsic to OOP, so it&#39;s important to understand the design patterns associated with it and the pros and cons of each.<br>
<br>cheers,<br>--<br>Shaun Fryer<br></div></div>