In our shared code base, a feature branch has just gone in that contains a model that is only made up of other models. I was just wondering if this was good practice to follow? An example I could give would be that there is a Fruit
model that contains properties such as Name, Price, Quantity
and another Stocks
model that contains ItemId, Amount, Name
. The shared model is set up in the following way:
FruitStock
{
Fruit Fruit {get; set;}
Stock Stock {get; set;}
}
This seems wrong to me and in a situation where something is required from both models then a lookup could be done and the value assigned to a variable. If I am wrong, however, then I guess I've learned something new today.
According to the class design guidelines, a class should have a single purpose. I'm not sure how much you simplified your request, but in this case it makes more sense to integrate ItemId into Fruit.
It all depends on the final purpose... if Fruit is something everybody has access to and Stock is limited to a certain amout of users, then this could also be a proper design.
Another approach could be to have FruitStock implement the interfaces IFruit and IStock