Now, I must preface this with the fact that I'm not an OO expert. In fact, the OO I tend to practice is better described as "aggressive refactoring and reuse" than pure Ivory-Tower OO.

I tend to think that a child class is really an instance of that class. A parent class is just a place to put information/capabilities that two separate and related classes will use. For example, If you have Games::Board::TicTacToe and Games::Board::Othello, the ability to place a piece on the board is going to be the same. The vector used to represent the board (barring size differences) is going to be the same. The fact that both use a size at all is the same. So, put that code in one place and have both inherit from it.

Now, I'm also a big fan of multiple inheritance, separating out functional areas. For example, Games::Board::Othello inherits from Board and Othello. Games::AI::Othello inherits from Games::AI, Games::Interface, and Games::Othello. And, so on.

Now, all of those superclasses are completely orthogonal, which is the only thing that makes this work. They do all inherit from Games::Base, but that defines things like BLACK, WHITE, and the like. (Granted, those definitions will actually be pulled out into other classes in the next iteration, but that's another story.)

Now, I've never worked on a "true" OO project in a "true" OO language. I know C++ and can read Java, but Perl is my major OO experience. (Just as it's my major functional experience, and I know that I have a bastardized idea of that, too.) The important thing, to me, is that it works (Criterion #1) and is maintainable (Criterion #2). It just may be maintainable only in my twisted mind. :-)

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.


In reply to Re: subclass data clobbering superclass data by dragonchild
in thread subclass data clobbering superclass data by princepawn

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.