javaclassnamingconvention

How unique should a class name be in Java?


Should I avoid naming my classes the same as classes in other external packages/libraries at the expense of sacrificing name conciseness and adding a little bit of complexity?

For instance, in my application I have a package named UIComponents that holds reusable components that certain parts of the GUI can use for common tasks. For example Form, Grid, Window. Since I am writing a simulator, should I use instead something like SimForm, SimGrid and SimWindow to avoid naming them the same as the components in some libraries I use?


Solution

  • Opinion-based, perhaps, but here's what I think: Is it going to be confusing?

    When I make card games, I tend to have a class named Card. When I try to use it for the first time in a file, my IDE asks me, "Do you mean my.package.Card or javafx.smartcardio.Card?" Well, obviously I have no interest in whatever smartcardio is, so it's not a problem for me to use Card as a name.

    Now suppose I was making a house designer using JavaFX. JavaFX has a class called Window, and I might use it for my application. Because of this, I'd say I want to avoid naming my own custom window class Window, and use something else like, HouseWindow...or something like that.