This allows elements to be deleted from the list without the Bar itself knowing about it (so its parent is set to the model but it can be removed from the model without reseting the parent).
Right now the Bar element has an AddToModel method and sets multiple parameters for both bar and model.
Maybe reverse this, make addeing bars the responsibility of the model, also chaning the property top IEnumerable to make sure bars cannot be deleted.
Also not sure why the bar needs to know who his parent is, can the bar be used in multiple models?
For exampe should this work:
(I have to think some more about the id matter)
public class Model
{
private IList<Bar> bars = new List<Bar>();
public IEnumerable<Bar> Bars => this.bars;
private IList<Material> materials = new List<Material>();
public Bar AddBarToModel(Bar bar)
{
this.materials.Add(bar.Material);
this.bars.Add(bar);
return bar;
}
}
As an example the Bar list in the model.
https://github.com/PawelBee/Guanaco/blob/797f7ebc20f034aa07a23216b141753812dfa121/Guanaco/Model/Model.cs#L54-L61
This allows elements to be deleted from the list without the Bar itself knowing about it (so its parent is set to the model but it can be removed from the model without reseting the parent).
Right now the Bar element has an AddToModel method and sets multiple parameters for both bar and model.
Maybe reverse this, make addeing bars the responsibility of the model, also chaning the property top IEnumerable to make sure bars cannot be deleted.
Also not sure why the bar needs to know who his parent is, can the bar be used in multiple models?
For exampe should this work: (I have to think some more about the id matter)
refering to https://github.com/PawelBee/Guanaco/blob/797f7ebc20f034aa07a23216b141753812dfa121/Guanaco/Model/Bar.cs#L130-L137