Advertisement

OO Design Question

Started by March 30, 2001 11:08 PM
1 comment, last by TheCage 23 years, 10 months ago
Ok, I''m going to be extending a baseball simulation I wrote to include more teams. Right now, there is only one team so I just use a Player class for all the players, and each player has their own set_Player_NAME_HERE() function to set their stats and such. My question is what would be the best way to expand this to include extra teams? I would rather not just throw in 1000 set_Player functions into the class. I am considering making some of the stuff in the Player class virtual, then deriving a class for a player of each team, so I''d have a Yankee''s class and a Angel''s class, for example. This would add a lot of extra files to my project, but it''s the best way I can think of right now. Is this an effective way of solving this problem? Can you think of a better way? Keep in mind I''m pretty new to this sort of stuff, but am trying my best to learn =).
Use a data file, or even a bunch of data files. You definetly do not want to derive a class for each new team. Make a CTeam object that has a list of CPlayers.

The maybe a CField obect that has two CTeam pointers, a HomeTeam & a AwayTeam. It could have a CPlayer *FirstBaseman, *Catcher, *Pitcher, *Batter, *ManOnFirst etc... maybe not, you could also add a Postion enum to the CPlayer class, which dictates their current job.

Finally a CGame class that has a CField list & a CTeam list. This way you can load data from files for the fields & for the teams.

[Field: Comerica Park]
HomeTeam= Tigers
City= Detroit
Distance_to_Wall= 324, 342, 326 //or whatever it is...

[Team: Tigers]
//I don't even know any of them anymore...

[Player: Cecil Fielder]
//Stats...


'course you can arrange the files anyway you'd like. Parsing text in is harder than using a binary format, but it's much easier to edit & add information to a text file than a binary one.

Edited by - Magmai Kai Holmlor on March 30, 2001 12:46:38 AM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
Thanks a lot man, I''m doing most of what you mentioned already (like a Baseball/game class and a Field style class). For some reason though, the data file idea escaped me. Thanks a lot!

This topic is closed to new replies.

Advertisement