Classes with more than one responsibility

Ideally, a class should have only one responsibility. When you design your class with more than one responsibility, it is possible to have interactions between responsibilities in the class that will make code modifications difficult and testing the interactions in isolation nearly impossible.

There are indicators that can clearly point out that a class is doing too much and has more than one responsibility. For example, when you are struggling with giving a class a name and you probably end up with the word and in the class name, it's a clue that the class does too much.

Another sign of a class with multiple responsibilities is when the fields in the class are used only in some methods or when the ...

Get C# and .NET Core Test Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.