I am currently developing a lightweight universal simulation. The goal is to allow people to subclass modeling and scenario objects for their domain-specific needs. Generics seemed like the right way to achieve this, but I'm afraid that I might be immersed in generic hell.
The object Simprovides access to simulation entities and controls the sim (start / pause / stop)
An object Scenarioallows you to populate Sim with simulation objects.
Sim:
public class Sim
{
public <T extends Sim> void loadScenario(Scenario<T> scenario)
{
reset();
scenario.load(this);
}
}
Scenario:
public interface Scenario<T extends Sim>
{
public void load(T sim);
}
The goal is to allow users to create MySimwhich extends Simand MyScenariowhich implements Scenario<MySim>for their domain.
eg. MyScenario:
public class MyScenario<MySim>
{
public void load(MySim sim)
{
}
}
, , scenario.load(this) Sim.loadScenario : (T) (Sim), , , this ( Sim), T extends Sim, , , Sim.
, ? ? , .