I am trying to figure out the best way to set up this model. I pretty much did it one way, but I am considering doing it another way. This is a learning experience so wasted time does not matter.
namespace FirstWay { public class CrateOfBags { public string crateId { get; set; } public string originCountry { get; set; } public List<BagOfApples> bagList { get; set; } } public class BagOfApples { public double weight { get; set; } public string bagId { get; set; } public List<apple> appleList { get; set; } } public class apple { public string appleId { get; set; } public string color { get; set; } public Boolean rotten { get; set; } } } //Or This
namespace SecondWay { public class CrateOfBags { public string crateId { get; set; } public string originCountry { get; set; } } public class BagOfApples : CrateOfBags { public string bagId { get; set; } public double weight { get; set; } } public class apple : BagOfApples { public string appleId {get;set;} public string color { get; set; } } }
Possible Questions
Apple Questions : How many Rotten apples were Delivered? Which Bags and/or which crates did rotten apples come from? First way: could loop through each crate, then bag,then apple and count. Second way: could loop just through apples and add parent properties to HashSet (one way to keep out duplicates)
Crate Questions. Find number of Crates From Each Country ? First way: Loop through just crates and keep a counting list, array, whatever. Second way: Would have to loop through all apples and only care about crates.
One Problem I ran into is I know very little about an apple as its own entity. I only know which crate it is from by starting the foreach loops from crate
But if I want to ask a question like "how many green apples are in a particular batch (by id)?" I am also having issues depending on the way.
It seems awkward to me to say that an apple is a child of a bag, like a dog is child of animal. However I like the idea of being able to freely move an manipulate apples, such as switch which bags they are in simply by changing the parent property bagid. I am not looking for solutions to the particular questions so much as just if one of these is better (more flexible, efficient, intuitive) then another, or if I am missing something completely such as using another technique. Thanks a lot.
P.S. This is not the real model, but a pretty decent representation.