Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^2: Object Oriented Perl - very basic guide

by choroba (Canon)
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
Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2015-10-10 18:48 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (257 votes), past polls