Two classes, those in two streams, need access to the list of cars.
In this case, cars are instances of a car class.
The flow of time steps has a class that implements its work. (Which reads the positions of cars.)
There is a class in carving that does its job. (Which updates line items.)
Each runtime class will access the vehicleโs objects to either update them with corrections information or read anything. You will need to synchronize use instance methods in the car class (or the container for cars mentioned below) that access the position, for example, so that different threads do not step on each other.
There are two similar implementation methods here.
1) Each time you create a car, you pass it to each of the two working classes. Each of them maintains its own list of all vehicles. If you get rid of the car, you must tell them both.
2) At the beginning, you give each of the two working classes a link to the container class for cars. Maybe just a list - a parallel list. Maybe a custom class. When you create a car, you specify the class of the container of the car (adding it). When you lose a car, you also talk about it.
As for the Simulation class, you want it to be informed of a change in vehicle position. Again there are two ways, but they are similar.
In both cases, you will have to pass an instance of the modeling class to the class that is performing the update. The simulation class has a method, such as updateCar() , which calls the update class after the update is completed.
1) Version 1 - a call to an instance of the simulation class indicates only that something has changed. The code in the modeling class will determine what has changed and what is connected with it, or it will just update everything.
2) Version 2 - a call to an instance of the simulation class will contain a list of any cars that have been changed. A modeling class does not have to search to find what has changed and it can only update changes.
The tricky part is that you have to remember that calls to this update method occur in the update stream. For example, if you use Swing to update the text on the screen, you will need to use SwingWorker to receive updates in the event stream.
If you cannot move this work to a safe thread, you need to make sure that all the right things are parallel or synchronized, so they don't step on each other.