Hi all,
I'm not sure this thread is in a right category.
I have a problem relating to software design. I'm developing a software to manage member ranking of a chess club in C#. The requirement is:
"Each member has a title in club. The title of a member is based on his/her Elo (a chess rating system), the number of competition he/she took part in and the his/her rank in those competitions. There are 7 titles: Pawn, Knight, Bishop, Rook, Queen, Gold Queen and Gold King. The condition of each title is:
- Pawn:
+ Elo: 0 - 499.
- Knight:
+ Elo: 500 - 799.
- Bishop:
+ Elo: 800 - 1499.
+ No of competition: >= 1.
+ Rank in competitions: 10 or higher.
- Rook:
+ Elo: >= 1500.
+ No of competition: >= 2.
+ Rank in competitions: 7 or higher.
- Queen:
+ Elo: >= 2400.
+ No of competition: >= 3.
+ Rank in competitions: 4 or higher.
+ Sex: female.
- King:
+ Elo: >= 2400.
+ No of competition: >= 3.
+ Rank in competitions: 4 or higher.
+ Sex: male.
- Gold Queen:
+ Elo: >= 2400.
+ No of competition: >= 5.
+ Rank in competitions: 3 or higher.
+ Sex: female.
+ The first Queen who satisfies above conditions or defeats current Gold Queen.
- Gold King:
+ Elo: >= 2400.
+ No of competition: >= 5.
+ Rank in competitions: 3 or higher.
+ Sex: male.
+ The first King who satisfies above conditions or defeats current Gold King.
These conditions can be changed in the future."

The problem here is that the conditions are not same between titles and those conditions can be changed in future. Can anyone help me? Thanks for your help!

I would create a class to hold the information for each member, something like:

enum Sex {Male, Female}

public class Member {
    public int ELO {get; set;}
    public int Competitions {get; set;}
    public int Rank {get; set;}
    public Sex Gender {get; set;}
    public String Title {
        get { // code to determine title here
        }
}

You might want to expand the default properties to prevent setting things like an ELO rating that is negative, etc.

I would create a class to hold the information for each member, something like:

enum Sex {Male, Female}

public class Member {
    public int ELO {get; set;}
    public int Competitions {get; set;}
    public int Rank {get; set;}
    public Sex Gender {get; set;}
    public String Title {
        get { // code to determine title here
        }
}

You might want to expand the default properties to prevent setting things like an ELO rating that is negative, etc.

Thanks for quickly reply. But the title of a member changes time by time. I mean that after a competition, his/her ELO and number of competition will be changed. And as a result, his/her title will be changed. I'm sorry because of not talking about it before.
Here I want to know how to design class diagram in analysis level. Now I have a Member class:

enum Sex {Male, Female}

public class Member
{
    public string ID {get; set;}
    public string Name {get; set;}
    public Sex Gender {get; set;}
    public int ELO {get; set;}
    public Title CurrentTitle {get; set;}

    // Some methods
}

And Title class:

public class Title
{
    public string Name {get; set;}
    
    // Propreties represent to condition

    public bool IsSatisfied (Member aMember)
    {
         // Check if satisfy
    }
}

I don't know how to represent condition of a title. And by the way, can you tell me how to store it in database?
Thank you very much!

Edited 5 Years Ago by levanlong: n/a

Thanks for quickly reply. But the title of a member changes time by time. I mean that after a competition, his/her ELO and number of competition will be changed. And as a result, his/her title will be changed. I'm sorry because of not talking about it before.

Of course it does, that's why there is a method for the get part of the Title property in my code. You'd recalculate the title anytime someone asked for it.

Here I want to know how to design class diagram in analysis level. Now I have a Member class:

Having a title class is bad design. It's a string value and doesn't need a class of its own.

can you tell me how to store it in database?

Before you worry about storing in a database, get your class designs down. Otherwise you'll just end up changing everything.

Hi Momerath,
But the title of a member depends on its condition. And the condition can be changed in the future. If we don't have Title class, how can we do that?

I seem to worry about storing data. But please explain it to me or give me some sugestions.
Thanks!

Since the method returns a title based on the attributes of the class (and doesn't store a value for title) when you ask for the title it is calculated based on the current values.

Basically you need to use if conditions inside the get Title attribute

if (ELO >= 0 && ELO <= 499)
{
    Title = "Pawn";
}
else
if (ELO >= 500 && ELO <= 799)
{
    Title = "Knight";
}

I think I understand what you said. But in my opinion, if we have a Title class with attributes are the condition of the title and a method called IsSatisfied(Member aMember) then it's more evolutional. We can read the condition from DB and user can change it. Here is my code:

public class Member
    {
        public string Name {get; set;}
        public string ID {get; set;}
        public Sex Gender {get; set:}
        public float ELO {get; set;}
        public string Title {get; set;}
    }

    public class Title
    {
        public string Name {get; set;}
        public float MinElo {get; set;}
        public int MinNoOfCompetition {get; set;}
        public int MinRank {get; set;} // in each competition
        public Sex Gender {get; set;}
        
        public bool IsSatisfied (Member aMember)
        {
             // Check condition here
        }
    }

Of course, I have a Competition class and a table COMPETITION in database. In this software, all information of a member and competitions need to store.

Is this right?

Edited 5 Years Ago by levanlong: n/a

No. You've created an entire class that copies another classes attributes just to add a method (IsSatisfied). Just put the method in the get method of the Title attribute. Which is what I originally said.

Thank you Momerath! And thanks to Singlem!
I think I solved my problem.

This question has already been answered. Start a new discussion instead.