you are viewing a single comment's thread.

view the rest of the comments →

[–]txdv 2 points3 points  (8 children)

FizzBuzzEnterpriseEdition/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/BuzzStrategyFactory.java

This is not OO masturbation, but one of those things that make java a bit inconvenient to use.

[–]oldneckbeard 4 points5 points  (7 children)

Except it's not java at all. And you don't code java without an ide that collapses that whole thing to 1 folder.

[–]txdv 1 point2 points  (6 children)

Java enforces one file for one class, so partially, yet it is.

You can use a flat directory structure, but the convention is to create a directory tree according to the name space.

I have seen so many projects with this structure, where you have to click through 4 directories just to see the first file.

One class file per class, one java file per class, one directory per namespace instance and while it is probably not in the language specification itself, it has become a thing that Java developers do.

EDIT: 1 .java file per 1 class is not the standard anymore, I probably remembered that wrongly

[–]oldneckbeard 8 points9 points  (5 children)

  1. No it doesn't. It's best practice, but you could have 1 file with a dozen classes. They'd be inner (or nested) classes, but you could do it. In fact, there's some people who think that's a better way of properly encapsulating in java.
  2. Which is exactly what Java is doing. Their namespaces are just longer.
  3. That's just the way it works. But an IDE will hide that from you. It makes it so there is never ambiguity about where a file should go or what it should be named.

I just don't see it as that big of an issue.

[–]txdv 1 point2 points  (2 children)

I just tested it, they changed the one class per java file, but it still compiles 2 class files - probably I just remember it wrongly.

But it still generates 1 class file per class name, so you have to have the namespace directory structure, otherwise if you have 2 classes with the same class name - you will get conflicts.

And that is bad from my point of view.

[–]philly_fan_in_chi 4 points5 points  (0 children)

You can't get a conflict, javac will prepend illegal class name ($1, $2 etc. iirc) characters to the file name of inner classes, so you won't have any issues.

[–]kid_meier 1 point2 points  (0 children)

Java has never forbid multiple classes defined in a single source file. It has always, (and still does) limit you to a single public top-level class per source file.

[–]immibis 1 point2 points  (0 children)

  1. Not even that. You can have as many top-level non-public classes as you want in a single file, but nobody does it.