I have a nested component structure, where my root element has a placeholder, which contains zero to many sub-components. Each sub-component has it's own price, which gets calculated inside the sub-component itself.
On the root component, I want to calculate the sum of the sub-component's individual prices. One way to go about this is to have the root component access all the sub-components found inside the given placeholder, fetch the price and calculate the sum. However, I feel that it's not really the proper way to do this. Instead, I would like to have some sort of pub/sub system, where the calculating of each sub-component price would trigger an event, that the root component could listen to etc. The problem is however, that the root component exists multiple times on the same page item, meaning that I somehow need to have a unique identifier that tells which root component each sub-component lives under.
Using Sitecore 8 with MVC, my question is how this best can be done, while still having a loose coupling between the subcomponents and the root components.