tags:

views:

111

answers:

3

I want to create a FIFA soccer solution in OOP (using C# in my case). For now, I need to represent: Teams, Groups (we have H groups), and Games.

What I did is creating those classes:

  1. Team - which contains several properties like teamName, score, wins etc...
  2. Game - which contains TeamA,TeamB (Both Team objects) and 2 properties TeamAScore,TeamBScore.
  3. Group - contains: Property GroupName, array of Team objects (size 4), List of Games, AddGame method
  4. FIFA - contains an array of Groups objects (size of array 7)

I need a method that prints all info of a team: including data from Team object (TeamName, score, wins...) + Team GroupName of the Team + All games of that team. For that I will have to create this method in the FIFA class, I guess.

I'm not fully content which this layout but can't really tell why. Any faults here? Suggestions?

A: 

My main concern with your design is the decision to put the games inside the groups. Starting today, there are inter-group games.

Also, why not rename your FIFA class to WorldCupTournament or something, so you can extend the whole thing to track this year's and 2014's cup, too?!?

grossvogel
Well, I can rename it , no problem with that.For now, I just need to represent the first stage of the tournament. Where would you save the games instead?
Guy Z
That depends doesn't it? Do you foresee a change in the future that will allow inter-group games? If so, then games belong in FIFA class, which knows all groups and therefor all teams.
eladidan
Look at the "has a" relationships to determine where things belong. A Tournament has Groups. A Group has Teams. A Tournament has Games. Games have Competitors (Teams).
Ryan
Thanks Ryan and eladidan! Those are helpful considerations
Guy Z
A: 

Regarding your last question, as to where to put the Print function. I would scale it down so that every Class has its own print. Since your print data-relevancy stops at Group level, I would stop there. Unless of course you follow grossvogel's advice and put the list of games in FIFA class. Something like this:

class Team{
...
public void Print(){
//prints TeamName, score, wins...
}
}
class Game{
...
public void Print(){
//prints a description of the game (Who vs Who, final score)
}
}
class Group{
private Team teams[4];
private List<Game> games;
public void PrintTeamInfo(Team t){
    t.Print();
    foreach Game g in games{
        if (g.TeamA == t || g.TeamB == t) //assuming you overloaded == operator for Team
            g.print();
    }
}
}

This scalability will allow reuse of code when in tomorrows assignment you are required to print all the FIFA's games and teams for instance. Like I said previously, if you end up deciding that games belong in the FIFA class, then PrintTeamInfo will have to move there too

Apologies if my code isn't well formatted. It's been quite a while since I wrote code in C#

eladidan
A: 

What are the inputs and outputs of your program?

Designing a good class structure is going to be difficult unless you have an idea of that.

kyoryu