Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: Object Oriented Perl - very basic guide

by choroba (Bishop)
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.

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

Replies are listed 'Best First'.
Re^3: Object Oriented Perl - very basic guide
by Preceptor (Deacon) 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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-06-24 23:01 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.