tags:

views:

41

answers:

3

Hello,

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.

+1  A: 

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.

Mike
A: 

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.

John Saunders
The biggest problem I have with breaking it up is that all my methods use the same variables. Shouldn't they stay in the same class then?
You want to strive for this:http://en.wikipedia.org/wiki/Law_of_Demeter
Mike
@user: they are _all_ using _all_ the same variables? You've got problems. How many of those variables refer to other objects? The need to refer to the same set of external objects does not indicate that these methods belong together.
John Saunders
They don't refer to external objects
If this really needs to be a single 4,000-line class, then it would be the first time I ever heard of a valid reason for such a thing.
John Saunders
I guess I'm missing the reason of why I should break it up other then it being easier to read but I really don't see the point in OOP in an application like this.
A: 

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.

derdo