0

I am working on a very basic driving simulation. I am trying to decide the relationship between the following objects: Freeway, Vehicle, Driver, ProximitySensors.

My real-world analysis suggests the following relationships:

A. Freeway has a vehicle: because a freeway can have multiple cars and a car can only have one freeway

B. Vehicle has a driver: because a vehicle can (usually) only have one driver and a driver can (usually) only have on vehicle

C. Vehicle has proximity sensors: only a vehicle can have apparatus for detecting nearby vehicles

However, when beginning to code this up, I've noticed a few oddities I want to straighten out. Here are the constructors I have come up with:

public Freeway(Vehicle car)
public Vehicle(Freeway freeway, Driver driver)
public ProximitySensors(Car car) // In order for it directly access the particular car's position
public Driver()

A lot of these are based on convenience / ease, so I am sure that I'm taking the shorter/incorrect approach. Here are a few questions I have encountered:

  1. First of all, I feel like the Driver should be controlling the vehicle, but as you can see from my other questions, I may be asking the Vehicle to ask the Driver to change lanes instead of the other way around.

  2. Often, I want the proximity sensors to access the freeway based on the vehicle's position (to detect other nearby vehicles), however with this structure, a Freeway has a vehicle and so I'm not sure how the proximity sensors (through the vehicle) will access the freeway unless I pass it to the vehicle as well.

  3. Does the car request permission from the Freeway to change positions? I wanted the car to be independent of the freeway and for it to have an accident if not programmed/performed correctly.

  4. What function should the Driver play exactly? They have a name, age, etc. but should they be the ones to call the proximity sensors on behalf of the car? Should the car do it directly?

  5. Should the Driver have its own method changeLanes(), which calls changeLanes() from the Vehicle which then calls its own proximity sensor function checkSide() which then operates on the Freeway?

When I started to code this, the relationships became murky without every object having access to just about every other object.

3
  • 1
    Why should a freeway have a relation to a car? It doesn't care about cars. It only has renovation cycles, max load/speed and the like. Commented Jan 5, 2017 at 23:37
  • What are the actual requirements for your simulation? Will human users be controlling the cars or will they be automated? What purpose does the simulation serve? How realistic must the physics be? If humans are controlling the cars, what are the inputs? Is it a 3D simulation or a 2D simulation? What data do you have in your road/map/environment? What are the rules of the road? etc. It's worth considering those kinds of questions before worrying too much about your implementation. Commented Jan 6, 2017 at 21:58
  • I have not fully thought it out as I am still exploring. At this point I am only establishing object relationships with no user control. 2D. Definitey no physics :) Commented Jan 10, 2017 at 18:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.