parse_account() of course would have to be able to determine the account type that the string defines, then call the appropriate account-object constructor. Each individual account-type package would provide a standard set of methods to access account information. E.g. to print out all the email addresses you'd implement a method called "email" within each package; it could be called like this:while (<>) { my($ssn, $obj) = parse_account($_); push @{$accounts{$ssn}}, $obj; }
A simple, individual "email" method would just look like:while (my($ssn, $acctlist) = each %accounts) { foreach my $acct (@$acctlist) { print $ssn, $acct->email, "\n"; } }
If you wanted to get fancy, all of the individual account-type packages could inherit from a more generic package; this would let you avoid having to create all these duplicate trivial methods.sub email { my $self = shift; return $self->{'email'}; }
In reply to Re: Balancing Complexities of Data Structures, Code and Readability
by kjherron
in thread Balancing Complexities of Data Structures, Code and Readability
by jlongino
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |