A Player can expose a controlled public operation while keeping its stored turn count and helper method private.
This complete class permits a caller to record a turn but not to assign the private count directly.
If the underlying C# feature is unfamiliar, use the lesson below while reading this example.
public class Player
{
private int numberOfTurns;
public void RecordTurn()
{
IncreaseTurnCount();
}
private void IncreaseTurnCount()
{
numberOfTurns = numberOfTurns + 1;
}
}Define a Player with a private turn-count field
Offer a public RecordTurn operation to callers
Inside it, call a private IncreaseTurnCount helper
The helper changes the stored count
Describe the visibility of each member separatelyThese words describe the class contract, not a sequence of runtime actions. Identify the types, stored members, operation inputs and results, and relationships before choosing compartments and connectors.
Player box.-numberOfTurns : int. Preserve the minus marker for private.+RecordTurn() : void and -IncreaseTurnCount() : void on separate lines.Compare this reference with the diagram you built in Violet. Layout may differ; the source meaning, labels, and relevant connections should agree.
External code can call RecordTurn. The Player implementation can call its own private helper, which updates the private field.