F
fishfry
Suppose I have a simple (flat) data structure, say for example a hash
with keys name, position, average representing baseball players.
In my program I might often need a list of these hashes, along with
methods that look up an object based on name, etc.
I have a class called PlayerList, which holds a list of players, along
with various methods for looking up, adding, and deleting players from
the list.
What are the pros and cons, in OO design terms, of having a separate
class for the data structure, say Player.pm, versus not having a
separate class?
For example in the former case I would add a new player to the list by
saying
my $playerList = new PlayerList(name=>'name', position=>'outfield',
average=>.300);
my $player = new Player();
$playerList->add($player);
versus
my $playerList = new PlayerList();
$playerList->add({name=>'name', position=>'outfield', average=>.300};
with keys name, position, average representing baseball players.
In my program I might often need a list of these hashes, along with
methods that look up an object based on name, etc.
I have a class called PlayerList, which holds a list of players, along
with various methods for looking up, adding, and deleting players from
the list.
What are the pros and cons, in OO design terms, of having a separate
class for the data structure, say Player.pm, versus not having a
separate class?
For example in the former case I would add a new player to the list by
saying
my $playerList = new PlayerList(name=>'name', position=>'outfield',
average=>.300);
my $player = new Player();
$playerList->add($player);
versus
my $playerList = new PlayerList();
$playerList->add({name=>'name', position=>'outfield', average=>.300};