Programming Practices – Does Having Many Using/Import Statements Indicate Bad Design?

programming practices

Typically, I see a few using statement at the top of class file. Example:

using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;

But in a project I am working on, on several occasions I see 20 or more usings/imports in one class file. Is this bad design? It seems to be that classes designed to do one thing should only rely on a few components.

Best Answer

It can indicate a bad design, yes. It might be that the class you're looking at is doing too many things, but it also might mean that the namespaces you're importing are really more coupled than the namespace separation implies. That may be because of over-engineer or over-abstraction, but it also might just be a design that doesn't align well with use.

That said, it's a smell - sometimes it leads you to something bad, and sometimes it's just a false alarm.