Should a Parent with Children have a DefaultChild, or should a Child have a Default property?
- by Stijn
Which of the following two models makes more sense? I'm leaning towards the first one because there can only be one default child.
The examples are in C# but I think it can apply to other languages too.
Here DefaultChild holds one of the items in Children.
class Parent
{
int ID { get; set; }
Child DefaultChild { get; set; }
IEnumerable<Child> Children { get; set; }
}
class Child
{
int ID { get; set; }
}
Here one of the items in Children has Default set to true while the others have it set to false.
class Parent
{
int ID { get; set; }
IEnumerable<Child> Children { get; set; }
}
class Child
{
int ID { get; set; }
bool Default { get; set; }
}
A concrete situation: a User in our system has one or more Customers attached. When logging in, if said User has a default Customer, they are immediately working under this Customer. If they don't, they have to select a Customer to work under. While logged in, they can switch between Customers.