There are three parties in my design:
- MSFT orderbook
- NASDAQ index (need to be recalculated when MSFT orderbook changes)
- MSFT strategy (need to be recalculated when MSFT orderbook or NASDAQ index changes)
So I attach both NASDAQ index
and MSFT strategy
to MSFT orderbook
like that: msftOrderBook.OrderbookUpdated += orderbookUpdated;
I also attach MSFT strategy
to listen for NASDAQ index
changes the same way.
I have following problems:
- Order is important. As I want
NASDAQ index
to be recalculated before recalculating strategy I should attachNASDAQ index
toorderBook
before attachingstrategy
. This is potential bug as I don't have easy mechanism to "guarantee" that I attach in right order... - When
MSFT
orderbook is updated, it notifiesNASDAQ index
and bothNASDAQ index
andMSFT orderbook
notifiesMSFT strategy
about update. SoMSFT strategy
receives double update but I don't need that. I want only one update because it's expected that when MSFT orderbook changes NASDAQ index will be changed too.
Questions:
- Is it good to rely on the order of
EventHandler
calls? and if it is not good what would be general solution to my problem? - Regarding second point I just want to ignore in
MSFT strategy
MSFT orderBook
update because strategy knows that every time orderBook is updated NASDAQ index updated too and so it would be enough to react only on NASDAQ index update. But probably you can suggest something completely different and better..