1

Hopefully this is a question that only needs a fairly quick answer, but I haven't had much luck finding something online that is in terms I understand!

Quite simply, I'm working on my first real project in Java, a text adventure, (using IntelliJ IDEA) and I was just wondering if I need to be splitting my code into modules? So, for my monsters, should I keep all of my monster classes within a module called Monsters, or can I just keep it in the same module?

I only ask because;
a) I wasn't sure whether it was a done thing in order to keep the project tidy and
b) When I tried to create a Monster module, I received a warning telling me that the files in this module wouldn't be accessible from the rest of the program, which seems to defeat the object to me...

Many thanks in advance for any advice!

Blisskarthik
  • 1,246
  • 8
  • 20
lordchancellor
  • 3,847
  • 4
  • 26
  • 26
  • possible duplicate of [Are there best practices for (Java) package organisation?](http://stackoverflow.com/questions/3226282/are-there-best-practices-for-java-package-organisation) (assuming by "module" you mean _package_) – kapex Jul 11 '14 at 12:52
  • What do you mean with modules? – AlexWien Jul 11 '14 at 12:56

2 Answers2

2

I believe you are referring to IntelliJ's concept of a module. As stated on their page:

A module is a discrete unit of functionality which you can compile, run, test and debug independently.

Modules contain everything that is required for their specific tasks: source code, build scripts, unit tests, deployment descriptors, and documentation. However, modules exist and are functional only in the context of a project.

So, modules should not be referencing the source code from other modules. They should essentially be completely different units.

As in thecbuilder's answer, you should look into using Java's packaging system instead.

Community
  • 1
  • 1
Christian Wilkie
  • 3,693
  • 5
  • 34
  • 49
1

By modules if you mean packages, then its a good habit to keep related classes in one package and distributing unrelated classes in different packages.

And to the thing, that the classes wouldn't be accessible, you'll have to make them public to access them from different packages.

More on package structuring :

  1. http://www.javapractices.com/topic/TopicAction.do?Id=205
  2. http://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html
  3. https://stackoverflow.com/a/3226371/3603806

For access specifiers :

access specifiers

Taken from : http://www.go4expert.com/articles/java-access-specifiers-t28019/

Community
  • 1
  • 1
Himanshu Tyagi
  • 5,201
  • 1
  • 23
  • 43