Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James:
Import statements! What's wrong with American made statements!
Maybe I need more sleep.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Warren Dew:
If I'm not mistaken, Eric is wrong about having to import into every class individually; can't one instead use fully qualified names?
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Jeanne Boyarsky:
I prefer the package.* apporach because you don't have 20 lines of imports clogging up the beginning of the code.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
With all due respect, having a class depend on 20 classes in other packages is a code smell - it indicates that the class likely is doing too much and violates the Single Responsibility Principle.
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Jeanne Boyarsky:
But sometimes you get a lot of imports through things you can't control. Our code generator generates commands with about 10 imports.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Warren Dew:
What do you think is a reasonable number of classes to depend on?
Here's a typical import list for me:
That's not quite 20, but it's for a pretty small class - the whole file is only 219 lines long, half of which are comments.
I find that if I want to maximize code reuse by using libraries as much as possible, I sometimes get up to 40 imported classes or so.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Warren Dew:
Sure. It's a list that allows the user to do certain manipulations, like additions and removals and reordering. I use such a list many times in my application, so it's worthwhile to make a reusable class.
To use a widget in Java, you need both a view-controller class and a 'model' class; that's why I end up with both a JList and a DefaultListModel. To make it scrollable, I need the JScrollPane. The JLabel is so I can have a title attached to the list, so I don't have to include it separately at a higher containment level. The awt.BorderLayout is needed so I can position the label relative to the list. I have to have JPanel so I can put all these things together into one reusable element. Like Stan said, Swing applications get long import lists in a hurry.
Unfortunately, the Swing 'model' classes are very limited and don't actually suffice for the data manipulation I need. I need to store the elements in a data structure of my own.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |