in reply to kind of effort required for learning OO perl ?!
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.#... 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
Celebrate Intellectual Diversity
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: kind of effort required for learning OO perl ?!
by chromatic (Archbishop) on Jul 29, 2010 at 19:25 UTC | |
by InfiniteSilence (Curate) on Jul 29, 2010 at 21:56 UTC | |
by chromatic (Archbishop) on Jul 29, 2010 at 23:08 UTC |