Small sample program that is easy to understand and work with. |
Output of above program. |
More complex part of a program that determines what code to run next. |
To organize this code, Java has classes which are used to put related code all in one file, while keeping less relevant code in another file. This helps with organization, similarly to how a book is divided into chapters.
Code all put into a single class without being properly organized. |
On the left is part of the original code when all of it is in a single class. As you can see, it's long and confusing with so much there that you can't easily see all of it at once.
Simplified code that is properly organized and distributed throughout multiple classes. |
However, below that image is a simplified version where I have put the code responsible for loading add-ins into a separate class. It is now easy to see that the single
Code for "loadJars()" method shown above. |
Below that is a third image, which shows the code that is run when the "loadJars()" method is used. This is much easier to understand and won't result in as much confusion down the road. As you can see, even the "loadJars()" method contains another method, "loadJar(f, false)" that loads each specific file.
By putting methods within other methods, the code is even neater and simpler to understand! This is known as object-oriented programming, where "all the functionality that's associated with an [object] is collected inside the code for the [Object] class" (Burd 170).
What do you think of the organization used in modern, object-oriented programming languages? Does it make the code look neater and less confusing, or is the condensed form easier to follow as the code doesn't jump around?
Works Cited:
Burd, Barry. Java for Dummies. 7th ed., John Wiley & Sons, 2017.