Inner Classes and Their Usage

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 4125 Views - Last Post: 15 April 2010 - 03:33 AM

#16 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: Inner Classes and Their Usage

Posted 13 April 2010 - 05:36 PM

@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).
Was This Post Helpful? 2
  • +
  • -

#17 cfoley  Icon User is online

  • Cabbage
  • member icon

Reputation: 1997
  • View blog
  • Posts: 4,149
  • Joined: 11-December 07

Re: Inner Classes and Their Usage

Posted 14 April 2010 - 02:05 AM

Thanks for the explanations there guys. Something to chew over. :)
Was This Post Helpful? 1
  • +
  • -

#18 DCEast  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 15-March 10

Re: Inner Classes and Their Usage

Posted 15 April 2010 - 03:33 AM

View PostMartyr2, on 11 April 2010 - 04:01 PM, said:

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.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2