I have some objects each hold a list of variables, and a list which holds all variables of these objects, for exampleclass A{   List<Var> varList;}class B{   List<A>   aList;   List<Var>   allVarOfAs;   // it is a common list which holds the members of varList of all members of the aList}Now if an object from varList in an an object of aList (an A object in B) is removed, how can I update the common list allVarOfAs?What is the pattern for such situation?
How to handle an aggregated list of the fields of multiple objects?
c#;object oriented;class design
The simplest solution is to NOT have the aggregated list 'allVarOfAs'. Instead make it a method or property which returns the aggregated list on the fly, but doing a SelectMany over aList. E.g. IEnumerable<Var> allVarOfAs {     get     {          return aList.SelectMany(a=>a.varList);     }}or List<Var> allVarOfAs{     get     {          return aList.SelectMany(a=>a.varList).ToList();     }}