Number of classes

I’ve got one very simple question.
How does the number of classes in J2ME influence on game speed.

For example I want to make a project that will have 10 classes. But I do not know will it be good
idea, because it may slow down my game. Of course, I can make the same project using just 4 classes, but
the code in those 4 huge classes would be unmaintainable.

What is your advice about the “optimal” number of classes in J2ME game?

The number of class definitions has zero impact on execution speed.
Object instanciation is what has a speed impact.
The number of classes does however impact on the memory footprint, and the jar size of your application.

The optimal number of classes is 2.
One that extends MIDlet, and another that extends Canvas.

[quote]The number of classes does however impact on the memory footprint
[/quote]
What do you meen? Can you explain in more details? Is there any difference for the Mobile
device between 1 class of 10 kb or two classes, 5kb each?

[quote]Object instanciation is what has a speed impact.
The optimal number of classes is 2.
[/quote]
If there is no speed difference I see no reason to put all the code in one class (that extends canvas,
because the one that extends MIDlet does almost nothing untrivial).

For example, when I write for MIDP 1.0 (that doesn’t have a game API) I always implement a TileSet class and
Sprite class if there is any animation.

What do you meen? Can you explain in more details? Is there any difference for the Mobile
device between 1 class of 10 kb or two classes, 5kb each?
[/quote]
yes, each Class definition has a memory footprint. The actual value is dependant upon JVM implementation and class file structure, however it is typically in the region of a few hundred bytes.

If there is no speed difference I see no reason to put all the code in one class (that extends canvas,
because the one that extends MIDlet does almost nothing untrivial).
[/quote]
I don’t understand what you mean by “MIDlet does almost nothing untrivial”.

However, I completely concur, placing all your code in a tiny set of classes is just plain ridiculous - your code will become completely unmanagable.

There are techniques and technologies to maintain the modularity of classes, while still gaining the benefits of having a small number of classes.

Many people use preprocessors, and while this approach will serve you ok for a time - you will eventually require a more advanced approach as preprocessors seriously inhibit debuggers and IDEs like Eclipse.

The more advanced solution is to perform class heirarchy transformation.
Several tools already exist to perform this task, 2 freely available ones are JAX and JOGA.
I can say no more.

Thank you for your anwer. I appreciate your opinion.