This is a general best practice question about creating parent / child relationships with objects. 

Let's say I have Wheel and Car objects and I want to Add a Wheel object to car object

```
public class Car{

    private List<Wheel> wheels = new List<Wheel>();

    void AddWheel ( Wheel WheelToAdd)
        {
            wheels.Add(WheelToAdd)
            //Some Other logic relating to adding wheels here
        }
    }
}

```

So far so good. But what if I want to have a Car property of my wheel to say which parent car it relates to. Something like this

```
 public class Wheel {

     private Car parentCar;
     public Car 
     {
        get
        {
         return parentCar
        }

  }

}

```

When adding the wheel to the car, at which point would you set the parent property of the Wheel? You could set it in the Car.AddWheel method, but then the Car Property of the Wheel object would have to be Read/Write and then you could set it outside of the AddWheel method, creating an inconsistency.

Any thoughts, many thanks in advance
['https://Stackoverflow.com/questions/3875021', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/425095/']
Bidirectional relationships tend to be very difficult to implement correctly. The prevailing advice here should be "don't do that, most likely you don't actually need it, and it will do you more harm than good."

If, after much careful consideration, you decide a bidirectional relationship is warranted, you can make the setter of the `Car` property `internal`, which doesn't fully protect against rogues setting unwanted values but it does limit the surface area significantly.
Question: Can the Wheel instance be assigned to a different Car instance later in time? 

1) If yes, the expose a public method to set the parentCar. You *could* make it a fluent method, for ease of code:

```
public class Wheel 
{
    private Car parentCar;

    public ParentCar 
    {
        get
        {
            return parentCar;
        }
    }

    public void SetParentCar(Car _parentCar)
    {
        parentCar = _parentCar;
        return this;
    }
}

```

Where you assign add the wheel, make the assignment:

```
void AddWheel ( Wheel WheelToAdd)
{
    wheels.Add(WheelToAdd.SetParentCar(this));
    //Some Other logic relating to adding wheels here
}

```

2) If not, just set the parent in the constructor.

```
public class Wheel 
{
    private Car parentCar;

    public ParentCar 
    {
        get
        {
            return parentCar;
        }
    }

    public Wheel(Car _parentCar)
    {
        parentCar = _parentCar;
    }
}

```