i'm not a Java-Newbie but I can't get my head around a problem occured recently.
I have to simulate a road system in Java. For sake of proper OOP, I've got a class Car and a class Street (and several others to manage the whole simulation of course^^). I already managed to simulate a jam on one road and have had no problem doing so.
OK, here comes the Question: I want to extend my simulation from one lonely street to a road system. So i thought of a class called something like "RoadSystem" which might have an array of streets and some sort of connection (I thought of 'knots') allowing cars to know where they can drive as they reach the end of the street they are driving on.
The problem is that I have no idea how to implement these knots. The car has to be able to ask the street "hey bro, I'm at the end of you, where can I drive now?" and the street should somehow know which knot has a reference to it and ask it for the streets that are also connected to this particular knot. How do I do this reference? I thought of an ID but this might get extremely slow for bigger road systems if the street has to search through the street-IDs of every knot in order to find its own ID there. Or am I missing an obvious solution to my problem?
Every help highly appreciated!
Greetings from Germany,
Ruffy