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
ResetScoreEach name suggests one responsibility.
A method named:
DoEverythingmight:
That makes the source harder to understand and change.
A focused method makes it easier to answer:
Before writing a method, state its job in one sentence.
For example:
If the sentence contains several unrelated actions joined by "and," consider whether the behavior is too broad.
Classes often name things:
Player
Team
MatchMethods usually name behavior:
DisplayRoster
StartMatch
ClearMessageThe 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.