Jump to content
  • Advertisement
Sign in to follow this  
AntonioMagic

How should I organize Java Classes?

This topic is 855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

While you are still learning and a beginner, order them in any way that makes sense to you.

 

Big code bases tend to subdivide code by broad feature areas (simulation, world, physics, assets, math, rendering, network, etc) then subdivide again, sometimes multiple additional layers, by functionality other criteria. 

 

The exact details are unique to every project. Naming things is a hard problem in computer science.

Share this post


Link to post
Share on other sites

The exact details are unique to every project. Naming things is a hard problem in computer science.

 

The two hardest problems in computer science:

1. Naming things

2. Cache invalidation

3. Off-by-one errors

 

But seriously, with Java, there is a crazy convention with many libraries to have a com.org.package.module.ClassName.  Don't worry about it.  Do what Frob says, and learn how to search for classes, objects, methods, and instances with your IDE of choice.  That makes finding things very easy, no matter where you put them.

Share this post


Link to post
Share on other sites

Organize it as you see fit and but try to group it in accordance with some rules that you see fit.

For example:

 - group common infrastructure logic into core/core-infrastructure/...

 - group APIs into core/core-api/...

 - split common GUI code into common gui modules

 - split specific GUI code (lets, say for example: JSF GUI) into each own

..........

 

For context, for a project I work on we have north of 600 maven projects for a code base of more than 1mil lines of code with our "heftiest product" (that is really just 20 lines of integration code) being 280 jars.

 

Also a pro-tip, if you use eclipse, type a resource/class name in window that you open with ctrl+shift+R and it will look for it in all projects that you have imported :)

Edited by busho

Share this post


Link to post
Share on other sites

If somebody had of told me how difficult it would be to just name things, when I started thinking about being a programmer. I would have thought they were horrible at their job as a programmer, or that they were an idiot. I've spent longer than I'd care to admit devising names, and renaming them later.

 

The names you choose help in 2 big ways.

1) They help you to design the big picture by abstracting all the functionality away behind the name.

2) A name implies functionality, as just mentioned. As such your code is easier to read, create, and understand.

 

I usually organize files according to purpose, which makes their names vital. I've not made any large projects in Java though, so I don't know how well it can be done there. These guys were spot on with naming things though, a terribly difficult task at times. Often you'll find you have a class that wants or sometimes needs to do multiple things, and you won't know what to name it to reflect that. Sometimes you'll have one class and it needs to be two classes, and you have the same problem.

Share this post


Link to post
Share on other sites

> Often you'll find you have a class that wants or sometimes needs to do multiple things, and you won't know what to name it to reflect that. 

 

 

Single Responsibility Principle helps with that. When it does more than one thing, make more than one thing.

 

You still have the struggle of naming the things. "Manager" is a banned object name at my present and my most recent past employer, partly at my recommendation. 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!