Structure with classes

My case is a bit difficult. I have no idea if it's even possible with java.



I have two classes, RuntimeCash and SandboxCash. Only shall be used, but RuntimeCash could not be avialable, because the class is simply missing. In this case, the programm should load the SandboxCash.

My problem is, who to compile code, where a class is missing.



Why would I want something like this?

At the moment I create a tool, where it should be posssible to use it independent or with my game engine.

The independent version works with a lite version of my engine, the other version use the game engine with heavy codes, bugs^^ and unecessary functions, if you don't use the game.

With a button you can decide, which engine you use.



If you only want to use the lite engine, you don't need my classes inside your project. Of course I can programm two different versions, but I think this solution is far more challenging and satisfying.



Which possibilities do I have?

hmm…

maybe look at dependency injection, guice from google is pretty cool…

ncomp said:

look at dependency injection

YES!  :)

ncomp said:

guice from google is pretty cool...

NO it isn't! IMO the only option is the Spring Frameworke here! www.springsource.org  ;)

Yes spring framework is definitely good and well known (great for enterprise applications, but I think it should work well for you).





Simpler solution though:



Of course if you have control over both engines you can just make an interface for both to share, that way you can use either engine and most of the code is hidden (ie: play either engine you want) as the whole area of code (besides selecting which engine) is oblivious there is a difference between the two etc…



The method of selecting then tries to load the heavy duty one but in the event it cannot, it loads the simple one. Or the user selects it. This can be done without IoC (Spring or Guice), though Spring with annotations probably wont be too hard either to inject dependencies… Though with only one dependency not sure if it really makes sense, but it is a good tool to learn.

Thanks for your suggestions! :wink:

Will take some time until if figgured it out completly, but seems to work.

Thanks