0

I'm trying to create a tennis tournament application. I'm strugging to find a way to accomodate results for singles and doubles without creating two tables.

I was wondering whether something like the following could be accomplished?

public class Result
{
    public int ResultId { get; set; }
    public int TournamentId { get; set; }
    public int Round { get; set; }
    public DateTime? DatePlayed { get; set; }
    public bool? Completed { get; set; }
}

public class ResultSingle : Result
{
    public int Player1Id { get; set; }
    public int Player1Score { get; set; }
    public int Player2Id { get; set; }
    public int Player2Score { get; set; }
}

public class ResultDouble : Result
{
    public int Double1Id{ get; set; }
    public int Double1Score { get; set; }
    public int Double2Id { get; set; }
    public int Double2Score { get; set; }
}

So then when I query Singles results it will query the Player table and when I query Doubles results it will look for Double Partners.

Is this right or would making it abstract make more sense?

Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
Jack
  • 319
  • 6
  • 16

2 Answers2

1

The answer here is actually dependent on the question will you ever instantiate a Result class by itself? if not then the abstract class would probably be a better option. There is nothing inherently wrong with what you have done, but from one standpoint an abstract class forces you to use the class as intended, so in this sense it is a little bit safer.

theDarse
  • 749
  • 5
  • 13
  • I guess I would be yes. I want to be able to list results, add/edit them so I will have to instantiate the class. – Jack Dec 07 '13 at 17:35
0

I agree with you that try to combine the two result table as one, because it will be frequently used for querying and showing data. In my opinion, you could define only one result class to store game result, but add a class named "PlayerTeam" to define payers information, although that must be according to your database structure. so my code is like this.

/// <summary>
/// game result
/// </summary>
public class Result
{
    public int ResultId { get; set; }
    public int TournamentId { get; set; }
    public int Round { get; set; }
    public DateTime? DatePlayed { get; set; }
    public bool? Completed { get; set; }
    public PlayerTeam Team1 { get; set; }
    public int Team1Score { get; set; }
    public PlayerTeam Team2 { get; set; }
    public int Team2Score { get; set; }
    //double flag
    public bool IsDouble { get; set; }
}

/// <summary>
/// player team, in single game, there is only one player.
/// </summary>
public class PlayerTeam
{
    public int TeamId { get; set; }
    public int Player1Id { get; set; }
    //if in single game, player2Id = 0 or -1, because there is only one player
    public int Player2Id { get; set; }
}
Scott Yang
  • 567
  • 2
  • 6
  • Thanks for the reply. I have thought of this option and having an indicator. But I thought why have a another table for doubles that includes singles as well.. when I could just link Result to PlayerId. But thinking about it, this makes more sense because how else would I know what tournaments that Player is in. Without querying the results table. So I think will implement this method. – Jack Dec 08 '13 at 12:16
  • but if that, when a player take part in many tournaments, both in single and double, so you need to query twice from different class? I think it's impossible to directly get that result, and why I design it as this, just want to separate the player info from result. – Scott Yang Dec 08 '13 at 15:41