4 ms·
Large classes are not always a bad thing. It's better to have a large class with 1K lines which you can break up at a later date than having lots of small class
by cryptica 7y ago
Large classes are not always a bad thing. It's better to have a large class with 1K lines which you can break up at a later date than having lots of small classes which have unclear or overlapping responsibilities and which will be difficult to reorganize later.
It's much easier to split up and categorize parts of a large blob of code than to re-categorize and merge bits and pieces of logic that are scattered all around.
- mark-r 7y agoWhat kind of coding do you do where a 1K class is considered large?
- cutemonster 7y agoWhat do you consider large? I think classes without internal state, can be large and still simple to understand. But if many mutable fields and internal constraints, then things can get complicated. Better keep such classes smaller
- mark-r 7y agoI would never argue smaller isn't better. But the code I work on every day tends to have much larger classes than that.
- fetbaffe 7y agoYes, key point is to separate classes if they have state or not. I have a simple convention in my code base, a repository does not have state, a service depends on repositories & can have state, thus a repository can have lots of methods (different ways of retrieving data) & a service is specialized & only have small number of methods. If an existing services does not match exactly what you need to do, you write a new service and reuse the same repositories.