3 ms·
You should split classes! But only where it makes logical sense, where there is a clear logical boundary. Splitting code as a way to visually organize code can
by ratww 5y ago
You should split classes! But only where it makes logical sense, where there is a clear logical boundary.
Splitting code as a way to visually organize code can lead to tight coupling, which tends to be worse than large classes.
If you split a class but there’s still multiple “points of contact” between both, it wasn’t a good split at all.
- selfhoster11 5y agoPeople split classes for visual reasons? That sounds unwise. I only ever split because the class is getting too large, or because some functionality is better off being moved to its own class. And those other classes also should preferably only have one or two methods exposed to the outside, there's nothing worse than a large surface area unless it's a library class.
- ratww 5y agoYep, you are completely right, this is extremely unwise. Problem is, a lot of material aimed at beginner developers basically instructs that. Also a lot of linter documentation shepherds users into doing it (I'm thiking of some Ruby linters here). > there's nothing worse than a large surface area unless it's a library class Yep, exactly. Even big classes are better than tightly-coupled classes with large surface area.