Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good practice to have a package/namespace and class within with the same name?

I am creating a new namespace and the most apt name for one of the class seems to be the same name as the namespace. Is this a good practice? If not, what is the alternative?

For example:

com.person
|--- Person.(java/cs)
|--- PersonDetailChecker.(java/cs)
|--- PersonNameGenerator.(java/cs)

Related questions discussing the same issue:

  • Should a class have the same name as the namespace?
  • How to avoid having the same name for a class and it's namespace, such as Technology.Technology?
like image 203
rkg Avatar asked Feb 17 '11 19:02

rkg


1 Answers

I would try to avoid that, since it can make your code harder to read Eric Lippert has written an article about this, which you can find here:

  • part 1,

  • part 2,

  • part 3

  • part 4

I've made the mistake myself a few times, and it certainly made it harder to read some of my code.

like image 99
Frederik Gheysels Avatar answered Sep 22 '22 03:09

Frederik Gheysels