How prolific should I be with classes? (A-Life example)

I'm currently writing an artificial life program. Currently I have classes related to neurons, networks, creatures, and environments.

Now I'm putting together my creatures. Creatures have eyes, ears, touch sensors, wheels... there's no limit to what a creature can have. Each of these components is quite different.

My questions is two-fold:

1) Should I create separate classes for each components? The (newbie) OO programmer in me says "yes!". This way everything remains entirely modular, and I can edit things very easily. However, I could easily end up with 20 classes related to my creature architecture alone. I worry that this will be very messy, and, as everything is just lumped together in one folder/package, it may be difficult to sort out by someone else. This brings me to my second question:

2) If I create separate classes for everything, is there a better way to organize them than just lumping them together in one package? It would make sense for me to bundle all the creature components, say, into their own little place, making a simple structure where we all know what's what. Is this possible?

2.1)Related: If all my classes are lumped together, my JavaDoc just lists all my classes in a single column, which is difficult to understand for the reasons above. Can I arrange my JavaDoc in some logical hierarchical fashion? I assume the answer to the question above will answer this one.

Thanks so much for your help!

[1486 byte] By [Asbestosa] at [2007-10-2 18:00:47]
# 1

Ok, I admit it, I should have looked a little more deeply into packages. I realize that this was the way to go.

Final question: Should I be sticking to the "dot" method of making hierarchical packages?

That is: I have my main package, alife. I have an engine and a GUI. In my engine I have creatures. Should my packages be

alife

alife.gui

alife.engine

alife.engine.creature

?

I assume that I should. However, the reason that I'm asking is because this still doesn't produce a hierarchical system. On the left column of my NetBeans IDE, all the ppackages are just listed in a column, not indented as expected. Likewise, the javadoc just lists all the packages in a column, paying no attention to what should be a part of what.

Any recommendations?

Thanks!

Asbestosa at 2007-7-13 19:19:43 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
There is no hierarchy to Java packages. For example, a class in alife.engine.creature would not have package access to something in alife.engine. The relationship between those two packages is exactly the same as the relationship betwee alife.engine.creature and java.util.Drake
Drake_Duna at 2007-7-13 19:19:43 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

Yes your instincts are correct and is called the principle of a single responsibility. All classes should maintain a single responsibility and a single esponsibility should be entirely encapsulated within a single class.

You may want to look at the Builder Pattern, which will allow you to build custom objects to a specification.

Yes packages will allow you to organise your classes effectively, the key principle you need to observer here is to have your classes dependent on the *common* denominator.

MartinS.a at 2007-7-13 19:19:43 > top of Java-index,Other Topics,Patterns & OO Design...
# 4
http://www.amazon.com/gp/product/159059388X/sr=8-1/qid=1145534666/ref=sr_1_1/104-4611487-0035939?%5Fencoding=UTF8
mchan0a at 2007-7-13 19:19:43 > top of Java-index,Other Topics,Patterns & OO Design...
# 5
Ok, thanks very much for all your replies!-Sam
Asbestosa at 2007-7-13 19:19:43 > top of Java-index,Other Topics,Patterns & OO Design...