user204588
user204588

Reputation: 1633

Large Class Refactor Rules

This is another question related to a question I asked a few minutes ago. If I have a class that I believe only has one responsibility but a lot of business rules and that class is large, about 4000 lines or more, is it OK to not re-factor the class into multiple classes.

Upvotes: 2

Views: 974

Answers (3)

derdo
derdo

Reputation: 1036

4000 lines is too much. Either you have 500 methods or you have really long methods. I cant see a way that can be managable. Seems obvious but I suggest you start with grouping similar methods/variables together. e.g. all cost data goes into productCost class etc. instead. Use query methods instead of calculated fields that are being used by many methods.

Upvotes: 2

John Saunders
John Saunders

Reputation: 161773

I would say "no". 4,000 lines is much too large.

I would examine the business rules to see if they don't imply the class is really composite. In particular, if it is possible to partition the set of business rules into sensible subsets, then it's likely each subset may indicate that your class needs to be broken into components, each with its own set of business rules, and that the rules should be parceled out among the components.

I'd also look at refactoring the business rules into a more compact representation.

Upvotes: 0

Mike
Mike

Reputation: 19697

A 4,000 line class isn't very maintainable. It might be hard to test pieces of the logic in isolation. A more practical reason to split it up is that multiple programmers can work on it in parallel if it is separated into multiple classes. This is a lot harder to do if it's one class.

You lose a lot of good software quality attributes by leaving this as a monolithic monster. There are better patterns to reduce its inner complexity, even if it truly is all cohesive.

Upvotes: 1

Related Questions