@cfoley: actually, with your current design, I do think that the has-a relationship is better than it. This is because MyStuff USES (or has-a) a CustomJPanel, as opposed to inner classes where it should be a member of or extend an object (a part-of relationship).
I actually prefer the has-a relationship that macosxnerd101 has in his example because, as baavgai said, it just makes for more clean code. Especially when writing games, where there are literally several DOZEN classes, it is better to make each class as short, concise, and extendable as possible. Nested classes are inherently against this principle, obviously with some exceptions to that rule.
The methodology of painting that you are using (passing the graphics object to other classes), however, is good. That allows the program to be object oriented and most importantly EXTENDABLE. It allows for major changes to go by easily without having to majorly refactor your code(such as adding a State Machine or another Panel for that matter).
17 Replies - 5174 Views - Last Post: 15 April 2010 - 03:33 AM
Re: Inner Classes and Their Usage
Posted 15 April 2010 - 03:33 AM
Am I a big proponent of it? Welllll.... Personally I rather choose other methods when showing people on boards like this just because inner classes don't always seem intuitive and if it is not intuitive then it can lead to confusion. However, if you are experienced, inner classes can save a lot of work if used properly and your design calls for it.
Awesome explanation! I thought you were one of my professor's at first because you used the Point class/struc as an example. Almost everyday I hear "If we have a 'Point p' and a 'Point A'....
Seriously though, great topic.