Responsibility

noun

say it: “rih-spon-suh-BIL-ih-tee” /rɪˌspɒnsəˈbɪləti/

The one job a class or object is there to do, which you can describe in a single sentence.

What is Responsibility?

Responsibility — The job a class or object is there to do, said in one sentence: "a Scoreboard keeps the score of one game." Anything that isn't part of that job belongs in another class.

class Scoreboard   // keeps the score of one game, nothing else
{
    public int Home { get; private set; }
    public int Away { get; private set; }
    public void HomeScores(int points) => Home += points;
}

In a sentence

  • “The Scoreboard's only responsibility is to keep the score, so printing moved to another class.”

Level: Apprentice · More OOP terms at this level

Updated