in reply to RFC on how I'm doing when it comes to writing objects?
Hi LadyAleena,
three things that caught my attention:
- Some comments would be nice, otherwise it's hard to deduce what the individual methods are supposed to do without seeing the data and other classes you're using.
- Always use 2-argument bless, i.e. bless $ref, $class, otherwise subclassing will not work should you decide to do it later.
- The whole blessing ritual doesn't actually gain you anything here as your methods as basically all class methods that you use like glorified procedures. The point of having objects (well, one of them) is to allow for more flexibility with regard to things you have hardcoded right now like the data file name and stuff like %add_lists_data without having to specify them each time. E.g.
Then you can call methods on that object an reuse the data you passed in on new(), and e.g. cache more data in your instance data as you read them (in case you're likely to need them again later):sub new { my ($class, $datafile, $accounts) = @_; return bless { file => $datafile, accounts => $accounts, }, $class; }sub acct_data { my ($self, $type) = @_; die "Invalid type, $type does not exist." unless defined $headings +{$type}; return $self->{data}{$type} if defined $self->{data}; return $self->{data}{$type} = { get_hash( file => data_file($self->{file}, "$type.txt"), headings => $headings{$type}, ) } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: RFC on how I'm doing when it comes to writing objects?
by Lady_Aleena (Priest) on Feb 04, 2013 at 20:40 UTC | |
by mbethke (Hermit) on Feb 05, 2013 at 04:58 UTC | |
by Lady_Aleena (Priest) on Feb 05, 2013 at 19:38 UTC | |
by mbethke (Hermit) on Feb 05, 2013 at 22:51 UTC | |
by Lady_Aleena (Priest) on Feb 06, 2013 at 19:07 UTC | |
| |
by tmharish (Friar) on Feb 05, 2013 at 07:04 UTC |
In Section
Seekers of Perl Wisdom