A method groups behavior under a name.
A single-purpose method performs one focused task that can be described clearly.
For a soccer program, examples might include:
DisplayRoster
StartMatch
ResetScore
Each name suggests one responsibility.
A method named:
DoEverything
might:
That makes the source harder to understand and change.
A focused method makes it easier to answer:
What is this behavior responsible for?
Before writing a method, state its job in one sentence.
For example:
Display the current team's name.
If the sentence contains several unrelated actions joined by "and," consider whether the behavior is too broad.
Classes often name things:
Player
Team
Match
Methods usually name behavior:
DisplayRoster
StartMatch
ClearMessage
The name should help a reader predict what the method does.
If one focused method produces the wrong result, the investigation area is smaller.
A method that changes unrelated parts of the application makes state changes harder to trace.
At this stage, you are learning basic methods.
Do not add:
Those ideas appear later.
Focus on a method that performs one clear task.