Let's say we have a Car, Wheel, and Brakes classes. A Car "has" four wheels so when an instance of Car is created, I want 4 instances of Wheels created at the same time. Likewise if I were creating a Motorcycle, I would want two instances of Wheels created. My question is how do I best create the Wheel instances and name them when creating a Car class?
Now suppose you want to assign the brakes to specific wheels- i.e.: FrontBrakes are attached to frontLeft, frontRight Wheels. Should I try to make a property in the Wheel class called AttachedTo? How do I assign ownership so to speak of the brakes to specific wheels?
public class Car
{
public Car()
{
Wheel frontLeft = new Wheel();
Wheel frontRight = new Wheel();
Wheel backLeft = new Wheel();
Wheel backRight = new Wheel();
Brake frontBrakes = new Brake();
Brake backBrakes = new Brake();
}
}
public class Wheel
{
public int Size;
public string Brand;
public Brake AttachedTo { get; set; }
}
public class Brake
{
public string Type;
}