Class

  • Thread starter Thread starter Mark Fisher
  • Start date Start date
M

Mark Fisher

I have created a class that records the number of games won by two players
playing a match.

The class has the following properties:

MatchLength
PlayerAGamesWon
PlayerBGamesWon

I also need to record whether the match is over (one player has won more
than half the games, if the score is 4-1 in a best of 7 then the match is
over).

My question is should this be a property or method, or is there no real
preference.

Thanks
 
Mark,

Mark Fisher said:
The class has the following properties:

MatchLength
PlayerAGamesWon
PlayerBGamesWon

I also need to record whether the match is over (one player has won more
than half the games, if the score is 4-1 in a best of 7 then the match is
over).

My question is should this be a property or method, or is there no real
preference.

If a game is over or not is an attribute of a game, not an operation a game
can perform, so I would vote for a property if calculating the property
value is a quick process.
 
Hi Mark,

in my opinion there isn't an special preference to use a method instead of
property or viceversa.

You can use a property with a Boolean variable to know if whatever player
has won the game. When you record the play won, the class has two
possibilities:
one of them will be call to other method of this class and count the result
and return if the game has finished and know the winner player.
other possibility is record the result and see if the game has finished and
change or no the Boolean property.

As to know if the game is finished or no is a simple instruction, I will use
the property instead of method, however, both could be possible.

I hope that helps.

Kind regards,

Jorge Serrano Pérez
MVP VB.NET
 
Mark,

In tennis they used in past an analoog clock. As a Brittain you should know
this better than others.

15
30
40 not yet thirth quarter because of a possible deuce (I thougth that this
was the reason)
Finish

In my opinion are this properties using an enum.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top