Critique my Java Class Names

Started by
15 comments, last by Ronnie Mado Solbakken 10 years, 6 months ago

I just want to know if the Java Class Names are appropriate so that when someone sees the class they will know what the class does based off the name. The game is a "match the word to the displayed image" type game.

JavaClasses_zpsad033fab.png

Advertisement

Naming is kind of a subjective thing but your naming is fine. At least, it conforms to what's normally expected in a Java project, and your classes are CamelCase, don't use any IWeirdImpl notation, and are descriptive (as far as we can tell - for all we know, your WordGenerator might be your main loop :)).

Are you building for J2ME? Anything else and I'd use package names, for convenience and convention.

You should start to put things up in separate packages. For now you can see everything in a single list, but that wont last long. Besides, separating functionality in packages kinda enforces some decoupling, or at least makes you think how your classes are really coupled.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Naming is kind of a subjective thing but your naming is fine. At least, it conforms to what's normally expected in a Java project, and your classes are CamelCase, don't use any IWeirdImpl notation, and are descriptive (as far as we can tell - for all we know, your WordGenerator might be your main loop smile.png).

Are you building for J2ME? Anything else and I'd use package names, for convenience and convention.

I am using Java SE(Standard Edition). Thanks for the feedback. It is nice to know the names are great.

Actually the main loop is in the Main.java. The Game loop is in Game.java.

Actually, an instance of WordGenerator class is created inside the Game class because the game needs to generate a new word whether the user got the word right or wrong.

Okay I will try to use packages too.

Depending on what i'm doing, i'll do it as you do. If I am working on a project with which I have a clear name for, i'll use a precursor of every function and class. Kind of like how OpenGL's functions have gl such as glScalef, though I don't care much for the data type indicator at the end. One of my recent projects I have been using clu and Clu; cluFunction and CluClass.

You should start to put things up in separate packages. For now you can see everything in a single list, but that wont last long. Besides, separating functionality in packages kinda enforces some decoupling, or at least makes you think how your classes are really coupled.

Thanks TheChubu. Yeah I will need to use packages now. biggrin.png

Depending on what i'm doing, i'll do it as you do. If I am working on a project with which I have a clear name for, i'll use a precursor of every function and class. Kind of like how OpenGL's functions have gl such as glScalef, though I don't care much for the data type indicator at the end. One of my recent projects I have been using clu and Clu; cluFunction and CluClass.

What do you mean by a precursor like a common prefix? So gl, clu and Clu will be your precursors in your case?

The reason why OpenGL functions have types at the end is because C doesn't supports function overloading. Thus every function has to have a different name, no matter if the parameters are different among functions with the same name. I wouldn't suggest doing the same if your programming language of choice does supports overloading, and the IDE is nice enough to tell apart between different functions.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Since there are classes and packages in Java to "partition the namespace", in a sense, there is IMHO no good reason to use a common prefix for all classes in your project.

On J2ME projects putting all classes into the default package was an optimization once but on J2SE projects you should generally use packages. Note that they conventionally go like tld.yourdomain.yourproject.maybeyoursubproject.yourpackage.yoursubpackagesetc in order to avoid conflicts globally but you are not limited to this, you can of course use any package names you want.

Since there are classes and packages in Java to "partition the namespace", in a sense, there is IMHO no good reason to use a common prefix for all classes in your project.

On J2ME projects putting all classes into the default package was an optimization once but on J2SE projects you should generally use packages. Note that they conventionally go like tld.yourdomain.yourproject.maybeyoursubproject.yourpackage.yoursubpackagesetc in order to avoid conflicts globally but you are not limited to this, you can of course use any package names you want.

Thanks! I use packages too.

This topic is closed to new replies.

Advertisement