So you plan to create groups dynamically in code and attaching items for those groups
If you can code this then you can code the testing of items in groups or not before and after.
I am sorry, I don’t mean to sound difficult, but I tried this approach and it was very cumbersome and difficult to implement in code. I went back to the drawing board and defined my groups and items for all the functionality I required.
There are no limits on the numbers of groups you can create
There are no limits on the numbers of groups an item can belong to
There are no limits on the nesting of groups
With proper planning and naming convention I have all the functionality I require.
I followed my own coding and the following design patterns: