Hello, you receive for sure good replies, but even if i'm not a ObjectOrientedMonk (read Damian Conway's ten rules for when to use OO), i recall that some framework for OOPerl gives theese method for free if you want: Moose and Moo.

In a very lazy and minimalist perspective i recall also a good trick to have the setter and getter method for free without extra packages using the AUTOLOAD (a Perl mechanism that intercepts all possible undefined method calls) trick:
package Person; use strict; use Carp; use vars qw($AUTOLOAD %ok_field); # Authorize four attribute fields for my $attr ( qw(name age peers parent) ) { $ok_field{$attr}++; } sub AUTOLOAD { my $self = shift; my $attr = $AUTOLOAD; $attr =~ s/.*:://; return unless $attr =~ /[^A-Z]/; # skip DESTROY and all-cap metho +ds croak "invalid attribute method: -> $attr()" unless $ok_field{$attr}; $self->{uc $attr} = shift if @_; return $self->{uc $attr}; } sub new { my $proto = shift; my $class = ref($proto) || $proto; my $parent = ref($proto) && $proto; my $self = {}; bless($self, $class); $self->parent($parent); return $self; } 1;
If i remember this code is from the old but still worth reading book Perl CookBook. In this book an entire chapter is dedicated to Object but starting from the very primitive concepts (the book is aged).

Even in the recent and very good book Modern Perl ther is tha chapter object oriented Perl that is very interesting.

About your other general questions... is a matter of aptitude i think. Remember also that an OO Perl program is generally slower than a normal one. Anyway setter and getter methods are needed if you want do something with that fat Object. And yes OO is a general way of thinking to data and behaviours and relationships.
Here at Perlmonks is a subject discussed many times: see super search: ?node_id=3989;HIT=object;re=N;BR;MR;M (notabely The Power of Objects Object-Oriented Perl - Introduction in The Perl Review Object Oriented Perl - very basic guide When to Use Object Oriented approach in Perl? (RFC))

HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: OOP's setter/getter method - is there a way to avoid them? by Discipulus
in thread OOP's setter/getter method - is there a way to avoid them? by tiny_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.