Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Object Oriented Perl - very basic guide

by choroba (Abbot)
on Jun 30, 2014 at 08:39 UTC ( #1091683=note: print w/ replies, xml ) Need Help??


in reply to Re: Object Oriented Perl - very basic guide
in thread Object Oriented Perl - very basic guide

Some hackers don't see it as an advantage. It doesn't catch typos in the constructor attributes:

my $obj = 'MyObject'->new( name => 'Typoed', debyg => 1 );

Also, the main point of getters and setters is encapsulation. Directly accessing the attributes breaks it. If you later decide to change the implementation, you need to change the code that touches the attributes as well.

لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re^2: Object Oriented Perl - very basic guide
Download Code
Re^3: Object Oriented Perl - very basic guide
by Preceptor (Chaplain) on Jun 30, 2014 at 13:51 UTC

    I've also had the discussion about whether you should have separate 'set' and 'get' methods, or whether having a single one is 'ok'. E.g.

    my $status_code = $object -> status; $object -> status ( "new_status" );

    I'm of the opinion that separating them out is good - static attributes you might think you can update in this way, because the paradigm of method calls is the same - as the method call you expect already exists, then it's only at run time you'll find that it doesn't allow changing, where if 'set_state' isn't present it's a bit more obvious.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1091683]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-09-20 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (151 votes), past polls