Currently, I'm having hard time trying to find a proper way designing event system for an API.
Situation: There are few classes (named WPoint, CPoint, OPoint...) which contains a lot of primitive type variables. All variables have properties and "changed" events. There is a class (named Frame) which contains a lot of primitive type variables and also few variables of type WPoint, CPoint... and such. Again, all variables have properties and "changed" events including variables of type *Point.
Finally, there is a class named FrameBox which is basically a WinForm-Control that contains a variable of type Frame (frame) and properties that gets/sets elements of the frame. FrameBox class have some *PointElement properties to simplify reaching some frequently needed data in frame. Likewise, it has *PointElementChanged events so one can connect them to event methods in designer.
Problem: All data needs to be fully accessible for other components to make the whole stuff going, and all system system blow up because I want to make event call-back to outer classes, here is an example:
frameBox.frame.wpoint.x = 4;
Above code is not only expected to call frameBox.frame.wpoint.XChanged
event but also frameBox.WPointXChanged
event. As the data needs to be modifiable we should be able to do frameBox.frame = new Frame()
and frameBox.frame.wpoint = new WPoint()
. Having one property and event for each field in Frame.* would be an overkill and not a solution as there are too many variables/events.
Let's say we registered our events (to sub-class events) at the constructor of FrameBox frameBox.frame.wpoint.XChanged += frameBox.WPointXChanged
, when a simple assign happens frameBox.frame.wpoint = new WPoint()
we no longer have frameBox.WPointXChanged
registered. I cannot force *Point constructor to get event parameters as I stated before there are too many events and it would result with code bloat.
Looking forward for any help, thanks anyone for spending time on helping me solving this!..