If your class relies on too many others, it will be coupled and fragile. A long import list is a good indicator.
TL;DR: Don't import too much.
Problems
Coupling
Single Responsibility Principle violation
Low Cohesion
Solutions
Break the class
Hide intermediate accidental implementation
Sample Code
Wrong
import java.util.LinkedList;
import java.persistence;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException
import java.util.Queue;
import org.fermi.common.util.ClassUtil;
import org.fermi.Data;
//We rely on too many libraries
public class Demo {
public static void main(String[] args) {
}
}
Right
import org.fermi.domainModel;
import org.fermi.workflow;
//We rely on few libraries
//and we hide their implementation
//So maybe transitive imports are the same
//but we don't break encapsulation
public class Demo {
public static void main(String[] args) {
}
}
Detection
We can set a warning threshold on our linters.
Tags
Coupling
Ripple Effect
Conclusion
We need to think about dependencies when building our solutions to minimize Ripple Effect.
Relations

Code Smell 61 - Coupling to Classes
Maxi Contieri ⭐⭐⭐ ・ Feb 4 '21 ・ 2 min read
More Info
Credits
Photo by Zdeněk Macháček on Unsplash
An indicator of a class that does too many things - so, that goes against SRP - is the number of imported namespaces.
If there are too many referenced namespaces ("using" directives in C#), it means that your class is doing too many things at once.
The fewer, the better!18:02 PM - 11 Oct 2021
Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it.
Alan Perlis

Software Engineering Great Quotes
Maxi Contieri ⭐⭐⭐ ・ Dec 28 '20 ・ 13 min read
This article is part of the CodeSmell Series.
Top comments (0)