In Java, is having ~50 data fields in a class of about 1000 lines a bad thing?
Edit: Thanks for the feedback. Has really opened my eyes and I’ll try to delegate functionality across more classes rather than have a single do-everything class. 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The question is very vague. The answer can be both yes and no. Yes, it’s a bad thing if you can break the functionality cleanly into more classes. No, it’s not a bad thing if the class is well focused and the only reason you got 50 fields is because you NEED them all there.
I have, for example, a class of 900 lines with 70 fields, but that’s because the class implements a bit of artificial intelligence and the parameters the AI algorithm uses are a lot of behaviors and thresholds which need to be defined there so that child classes tweak them. In my case, I would say that it’s not a bad architecture, and my 14 years of software development seem to agree ::- ).
Sure, if the class would go over 1000 lines, I could break it down further into 2: movement AI and attack AI, but for now, it really makes sense in the context of my project to have it together because movement AI and attack AI are never applied independently: they work together, they should be in the same class. If I ever have to make an object which ONLY needs movement AI, then by all means, I’d break it apart into 2.