I didn’t know what else to title this post, so if you have a better title, feel free to edit.
I have two classes: Form and Field.
Form has a property called Fields that is a List of Field objects.
Form has a property called Prefix.
Field has a method that needs to use the Prefix property of the Form that contains it.
Here is what I am doing now:
class Form
{
private List<Field> fields;
public string Prefix { get; set; }
public void AddField(Field field)
{
field.Form = this;
fields.Add(field);
}
}
class Field
{
public void RenderHtml()
{
// render html element with ID attribute
// prefixed with the parent form's Prefix property
}
}
How should I do this?
I would do this: