@Joan, This is an interesting problem! I don't know what the ideal solution is, but maybe you could create three classes: subscriber, contract and broker. The broker class would manage the other two. It would behave something like this:
- Maintain a structure marketFeeds with dynamic fields feedname. Each field has two subfields: subscriberHandle and listenerHandle.
- Input handle to new contract ( broker.addContract(contractHandle) ).
For each feed name, see if it is one of the field names in marketFeeds.
If it exists, add contractHandle to list of handles maintained by the corresponding listener ( i.e., listenerHandle.addContract(marketFeeds.feedName.contractHandle)).
If it doesn't exist, add a new subscriber object and a listener for that object. Give the handle of the contract to the listener.
When a listener is told of a change in the market feed, it calls each of the handles with some command like contractHandle.reactToMarketChange(feedName,NewValue).
When the contract is terminated, send its handle to broker.deleteContract, which then does all the necessary actions on marketFeeds.
Best Answer