5

I am about to embark on a personal JAVA project in eclipse where myself and a friend create a game server, game engine, and a game based on an existing card game. The game server will come last, but for now I'd like to concentrate on building the card game engine followed by the game itself.

In school, we would just create packages like gameEngine.whatever and then the different games would be in packages like game.gameName.whatever. I was thinking of making the game engine its own separate project and then have the game be an individual project as well, instead of having them all in one project and separating them based on packages, like I've done in school. In my internships, we have multiple projects working together, but have not touched on that in classes at all.

Is there any difference in doing it one way versus the other? Or are they basically equivalent? Thanks!

codenaugh
  • 857
  • 2
  • 12
  • 27
  • The benefits of packages versus modules is a little too broad for this site. They are very different and have very different benefits. I would suggest further reading. – Boris the Spider Jun 29 '14 at 16:18
  • I tried to find info on my own, but came up empty handed... Also, as I mentioned, my schooling does not discuss this sort of thing. I will try to look up packages versus modules. – codenaugh Jun 29 '14 at 16:24
  • If you can suggest something to read, I would be grateful. – codenaugh Jun 29 '14 at 16:24

3 Answers3

7

If I understand your situation correctly, you should not worry too much about code organisation at this point. Of course there are some projects where it is clear upfront as to where what goes in. Not so in many cases.

In your case, as you start implementing things, you'll gain more clarity on the direction to take and the organisation. One advantage of using IDEs like eclipse is that you can refactor code (both packages or even move packages/classes across projects) at a later stage. For eclipse, the code is not just files/directories. It is looking at the parse tree and so can let you move around a lot of fine stuff safely - moving code across packages or projects is among the most trivial things it can do.

Just focus on what you have to do and try to make progress with the real stuff. If you have to worry about multiple projects, you'll know when to. I'd suggest starting off with something like:

  • Create one project for now. First find a standard and unique package prefix. Say you decided to go with something like "org.abc" (just an example not a good one)

  • Now start working on your project. As you keep adding classes, focus on organising well just package wise. Keep adding packages as you go. For instance..

    • org.abc.game.engine

    • org.abc.game.util

    • org.abc.game.games.mario

    • org.abc.game.engine.phy

    • org.abc.game.server

    • org.abc.game.common

    • ...

After a while when you want-to, you can create the new projects. For instance you can decide to

  • call the current project as GameMario

  • move the entire org.abc.game.common and org.abc.game.util with some files to a project called GameCommon. The same package can exist (and in many cases do) in two projects

  • move the org.abc.game.engine, org.abc.game.server and all their sub-packages to a new project GameServer and continue adding game server code in that project

  • Both GameMario and GameServer will have a project dependency on GameCommon

ac3
  • 196
  • 2
3

I'd say you should make a separate project for "X" if "X" can be used on its own or there are (or could be) at least 2 different projects that use "X". Otherwise, a package is fine.

  • so it is just preference, basically, or common to do this type on thing with multiple projects instead of packages... no pros or cons to each? – codenaugh Jun 29 '14 at 16:12
  • 1
    Normally projects do things called "modules", which some IDE's support. I honestly just prefer putting separate programs in separate project entirely, makes the whole thing down the road much easier. (I'd also personally recommend against using eclipse) – Rogue Jun 29 '14 at 16:13
  • 1
    @clanier9 as I said, it depends on how you want to use it. I don't think it's just a preference, because once you want to use a package from a project (in another project), you have to depend on the whole project, which can include lots of things you don't need (in other packages). – aditsu quit because SE is EVIL Jun 29 '14 at 16:15
1

Using multiple projects instead of packages has some advantages
You can compile, test and run the server, client and engine separately. I know this is possible with packages as well, but it would be cleaner. If there is a code collaboration like in a git, it will be way easier to manage.

If you are dubious about using the engine as a module in the client, you can always use one project as a library of the other. That way, you can keep the work separate, but use the functions without a hassle while developing the game.

On the other hand, there are some disadvantages. Your code will be three separate entities. So, if you're used to moving one jar file everywhere and issuing arguments to a single class telling it which module to run, this project approach may not work.

It all comes to your application and your style. If I were you, I'd do three projects.

Good luck.

Tharaka Devinda
  • 1,952
  • 21
  • 23