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!)?
3
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.
0
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.