Java – good programming practice for structuring java project

designjavapatterns-and-practicesswing

I have a Java project that is getting to be relatively large (a few thousand lines in all, I'd say). It's definitely a lot larger than what I've dealt with before, being that I am still a relatively new programmer.

I have a class structure with my swing components and other classes I have made that, more and more, is becoming confusing. Even as a beginner, I can tell this wouldn't be considered "good programming practice". It's somewhat difficult to explain, and I cannot simply copy/paste code, as this is really dealing with the whole program. But I will do my best to explain…

As an example, I have a "Minion" class, and Minion objects will sometimes do something that needs to update a "levelGUI", an extended JPanel. How do they access this levelGUI? I will tell them something like "Game.getLevelGUI().someMethod()" and that just looks sloppy. Am I wrong?

The problem is that I have gotten ahead of myself in actual programming, relative to my understand of how the structure of said program works. I think what I will end up with, if I continue down this path, is a program that works as I intended, but with poor readability and great difficulty in altering down the road.

If this seems a difficult question to answer, links to articles which could explain how a large hierarchy of objects effectively "interact" or something to that effect… would be VERY helpful (I'm not being lazy, I have looked and looked, trying to find something).

Best Answer

My all-time favorites resources about organizing guis are by Martin Fowler

http://martinfowler.com/eaaDev/uiArchs.html

http://martinfowler.com/eaaDev/OrganizingPresentations.html

and the patterns described there

Related Topic