The heart of the big benefits from OO is encapsulation, not inheritance.
Interesting observation, open to debate. I am new to OO, and intuitively, it is inheritance that I see as a bigger benefit than any other OO properties. In fact, intuitively, inheritance is what I understand better than encapsulation or polymorphism, etc.

Yes, multiple inheritance (MI) can cause a lot of problems, especially if using modules that were built by others, and hence, were not designed from ground up to be inherited from in conjunction with other modules. But life is complicated, and more often than not involves MI. After all, we all inherited from a dad and a mom, with hopefully no clashes and dire consequences.

That said, should not my approach, stated in my second post above, avoid the problems of same-named methods clashing and overriding each other? Except, it doesn't work all the way. Here is the real code I am trying out. I want to use a config file and connect to an email server. For this, I use Config::Simple and Mail::IMAPClient. Thus far I was using it normally and it works. Lately I decided to OO-ize it thusly --

package Mypackage; use Config::Simple; use Mail::IMAPClient; use strict; sub new { my ($class) = @_; bless {}, $class; } sub load_config { my ($self, %a) = @_; return new Config::Simple("$a{cfg}"); } sub connect_to_imaphost { my ($self, %a) = @_; return Mail::IMAPClient->new( Server => $a{IMAP_HOST}, User => $a{EM_UNAME}, Password => $a{EM_PWD}, Uid => 0, Debug => $a{DEBUGGING}, ); } sub other_methods... {} ### and then, in my script... use Mypackage; my $a = Mypackage->new(); # $a has all the methods of Mypackage $f->load_config(cfg => "my.conf")->import_names(); # this works and imports all the config vars my $imap = $a->connect_to_imaphost( server => $IMAP_HOST, user => $EM_UNAME, password => $EM_PWD, debug => $DEBUGGING, ); my $msg_count = $imap->message_count("$INBOX"); # the vars above have been imported via Config::Simple # the above, however, fails with the following ##Not connected at ./myscript.pl line 48 ##Error sending '1 STATUS inbox (MESSAGES)' to IMAP: at ./myscript.pl + line 48

In the above code, instances of B and C are made only when called for. In a way, I have achieved encapsulation, and made A inherit the properties of both B and C, but only when desired. Thereby, hopefully, avoiding any problems.

Question is -- is the above code ok? If yes, why is it not working. If no, what am I doing wrong?

Many thanks.

--
when small people start casting long shadows, it is time to go to bed

In reply to Re^2: Understanding 'Multiple Inheritance' by punkish
in thread Understanding 'Multiple Inheritance' by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.