Say I have a class as follows
class FootballPlayer
{
public string Name { get; set; }
public string TeamName { get; set; }
public int CareerGoals { get; set; }
public int CareerAssists { get; set; }
public int CareerPasses { get; set; }
public int SeasonGoals { get; set; }
public int SeasonAssists { get; set; }
public int SeasonPasses { get; set; }
public int CurrentMatchGoals { get; set; }
public int CurrentMatchAssists { get; set; }
public int CurrentMatchPasses { get; set; }
}
But I want to organize it better, so how can I do it. At the moment i tried something like this -
class CareerDetails
{
public int Goals;
public int Assists;
public int Passes;
}
class CurrentMatchDetails
{
public int Goals;
public int Assists;
public int Passes;
public bool IsCaptain;
}
class GeneralDetails
{
public string Name;
public string TeamName;
}
class SeasonDetails
{
public int Goals;
public int Assists;
public int Passes;
public int MatchesPlayed;
}
class FootballPlayer
{
public CurrentMatchDetails CurrentMatchDetails { get; set; }
public SeasonDetails SeasonDetails { get; set; }
public CareerDetails CareerDetails { get; set; }
public GeneralDetails GeneralDetails { get; set; }
}
A few things I do not like about this
- I have to make the classes (the SeasonDetails, CareerDetails etc) public
- I have to instantiate all of these classes separately after instantiating the FootballPlayerClass
But I am not sure if it is the best practice. I was thinking of creating a embedded class within the class FootballPlayer.
I am going to be using the class in a WPF application and going to implement INotifyPropertyChanged
on my FootballPlayer
class. By using the method above, I am going to have to imlpement INPC on all of the classes such as CareerDetails
etc. So what should I do instead or should I stick with what I have?
I may have another base class called 'FootballTeam' which could have a sub-class named CurrentMatchDetails as well - It may look like this
class CurrentMatchDetails
{
public double TimeElapsed;
public string RefereeName;
}
so I should be able to access properties like this teamObject.CurrentMatchDetails.RefereeName or playerObject.CurrentMatchDetails.Goals;