According to most online sources OO programming involves three basic elements: inheritance, polymorphism, and data encapsulation (see references included in the code). Some examples of basic ways to achieve these are below.
#... http://www.cs.mun.ca/~donald/bsc/node12.html # INHERITANCE package dog; sub new { my $class = shift; return(bless({'puppies'=>15},$class)); } sub get { my ($self,$name) = @_; return ($self->{$name}); } sub set { my ($self, $name, $newvalue) = @_; #this is silly but saves space $self->{$name} = $newvalue; return $self->{$name}; } sub bark { return 'woof...I INHERITED this capability.'; } package cockerSpaniel; use parent -norequire, qw|dog|; sub new { my ($class) = @_; return(bless(dog->new(),$class)); } sub bark { my ($class) = @_; return ($class->SUPER::bark() . '..but then overrode it'); } package main; my $doggie = new cockerSpaniel(); $doggie->set('puppies',29); print qq|\nHere are the cockerSpaniel's puppies: | . $doggie->get('pup +pies'); my $realdog = new dog(); print qq|\nHere are the parent dog's puppies: | . $realdog->get('puppi +es'); # POLYMORPHISM, or dynamic binding of function calls print qq|\n| . $doggie->bark(); # Data Encapsulation # There are numerous techniques. Take your pick: # http://www.csse.monash.edu.au/~damian/TPC/1999/Encapsulation/Paper.h +tml
The above, with the reading, should take only about an hour or so to learn. It is good, in my opinion, to learn the old non-Moose way of defining classes since there is so much code out there that uses these techniques. The problem that I have seen with OO programming in general has little to do with the techniques or semantics -- it has to do with learning to think in an object oriented way. For this I recommend using something entirely outside of the scope of a particular language. I recommend reading Object Thinking by David West (don't worry that is was published by Microsoft Press...this book was published under an experiment where no Microsoft technologies were discussed in the book). Here you will learn not just terminology and the mechanics of how to migrate from top-down to OO, but how to use nomenclatures and tools (CRC cards, for instance) that will help you describe and analyze problems before you write code.

Celebrate Intellectual Diversity


In reply to Re: kind of effort required for learning OO perl ?! by InfiniteSilence
in thread kind of effort required for learning OO perl ?! by Anonymous Monk

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.