I am redesigning how events (related to data) are handled for existing code (in C++). The events to be handled are DataTable related events, and XmlNode related events.
I’m wanting to create a general super class with virtual functions (calling it EventManager) in order to provide consistency across the application.
I plan to have the following virtual functions in the EventManager:
DataChanged(EventArgs arg)
DataChanging(EventArgs arg)
DataInserted(EventArgs arg)
DataInserting(EventArgs arg)
DataRemoved(EventArgs arg)
DataRemoving(EventArgs arg)
I have used EventArgs as a parameter because the others (XmlNodeChangeEventArgs, DataRowChangeEventArgs, DataColumnChangeEventArgs) are derived from it. But by using it in the virtual functions, I will have lost information unique to the derived event args.
My question, how should I be designing/handling this super class and the virtual functions in order to have a general class that manages events, but can still properly map (with all information needed) to the derived classes?
I did my best to explain my situation, but please feel free to ask questions to clarify the question. I’m really looking for well thought out answers, so I’m open to improving my question!
Thank you in advance for your time and patience! 🙂
Pass the arguments by
reference, passing by value just adds an additional overhead.But by using it in the virtual functions, I will have lost information unique to the derived event args.
You can use
dynamic_castand check the validity of the downcast, no information will be lost.