I have two client types, an "Observer"-type and a "Subject"-type. They're both associated with a hierarchy of groups.
The Observer will receive (calendar) data from the groups it is associated with throughout the different hierarchies. This data is calculated by combining data from 'parent' groups of the group trying to collect data (each group can have only one parent).
The Subject will be able to create the data (that the Observers will receive) in the groups they're associated with. When data is created in a group, all 'children' of the group will have the data as well, and they will be able to make their own version of a specific area of the data, but still linked to the original data created (in my specific implementation, the original data will contain time-period(s) and headline, while the subgroups specify the rest of the data for the receivers directly linked to their respective groups).
However, when the Subject creates data, it has to check if all affected Observers have any data that conflicts with this, which means a huge recursive function, as far as I can understand.
So I think this can be summed up to the fact that I need to be able to have a hierarchy that you can go up and down in, and some places be able to treat them as a whole (recursion, basically).
Also, I'm not just aiming at a solution that works. I'm hoping to find a solution that is relatively easy to understand (architecture-wise at least) and also flexible enough to be able to easily receive additional functionality in the future.
Is there a design pattern, or a good practice to go by, to solve this problem or similar hierarchy problems?
EDIT:
Here's the design I have:
The "Phoenix"-class is named that way because I didn't think of an appropriate name yet.
But besides this I need to be able to hide specific activities for specific observers, even though they are attached to them through the groups.
A little Off-topic:
Personally, I feel that I should be able to chop this problem down to smaller problems, but it escapes me how. I think it's because it involves multiple recursive functionalities that aren't associated with each other and different client types that needs to get information in different ways. I can't really wrap my head around it. If anyone can guide me in a direction of how to become better at encapsulating hierarchy problems, I'd be very glad to receive that as well.
n
with an in-degree of 0 while every other vertex has an in-degree of at least 1? Is every vertex connected ton
? Is the path ton
unique? If you could list the properties of the data structure and abstract its operations to an interface -- a list of methods -- we (I) might be able to come up with an implementation of said data structure.O(n)
algorithms for a well-defined data structure I can work on that. I see you didn't put in any mutating methods onGroup
and the structure of the hierarchies. Am I to assume that these will be static?