1

I've written a program in Java, it's only fairly small and I started programming and ended up just building one big class with everything inside it.

The program works fine and exactly how I wanted it to, however, when writing up the documentation I've realized that it doesn't follow any sort of architecture pattern like MVC or 3-tier and seems most like a monolithic system. Is this likely to be detrimental?

Maintainability is fairly important but the code is well commented and could be extended fairly easily if somebody wanted to add an extra algorithm for example. I'm just wondering if this is bad practice and whether it will be looked down upon?

It is for part of a project so it will get assessed, I do have time to split it up into classes but it could be unnecessary work I feel and I wouldn't really know how to split it up. When I say a big class, its all relative but its about 1750 lines of code.

I guess the main question is; it works as it is so is there any need to split it up into classes? Are monolithic systems particularly bad (not sure if it even is a monolithic system!)?

  • possible duplicate of How do I prove or disprove "god" objects are wrong? – gnat Apr 16 '14 at 12:49
  • 4
    Not every code has to be OOP, but at that size it's likely that you could have structured it better. And there is absolutely no need to use complicated design patterns or grandiose-named architectures for their own sake. If you like, you could post some relevant excerpts of your code on Code Review to get some feedback. – amon Apr 16 '14 at 12:51
  • One giant class implies no other data structures (you aren't using inner classes). Are you passing any other structured data round as List<Object> or Map<String, Object>? Or is there just no other structured data you are working with? – user40980 Apr 16 '14 at 14:55
6

Think about it in these terms:

  • If I were to look at it with the purpose of modifying some code, how long will it take me to find where to do so without talking to you first?
  • Is some code repeated? Can you avoid that?
  • What if you need to invoke a method from another class - can you do it easily?
  • Did you write unit tests?
    • Do they pass?
    • If not, try to write some - probably by doing so it will become apparent how you need to refactor your class.

Lots have been written on this topic, but you need to be bitten by this before you can truly understand what are its consequences.

2

You have written an application which is a God Object, maybe even with a Megamoth (MEGA MOnolithic meTHod).

This style of programming isn't object-oriented. It is procedural. There is nothing wrong about procedural programming per-se. There are many important programs which work very well and are sufficiently maintainable even though they are completely procedural. But usually these aren't written in object-oriented languages like Java.

As you noticed it is not impossible to write a procedural program in an object-oriented programming language like Java. But the whole philosophy of Java is build around object-orientation. When you do not use it, you are missing out on the most useful features of the language and its API while having a lot of syntax padding which has no benefit to you at all.

Not every problem is suitable for an object-oriented solution. Some problems fit much better into a procedural programming style. When you encounter such a problem, you would be well-advised to pick a procedural programming language to solve it. That's why there are so many programming languages available: So you can pick the right tool for every job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.