Events and references pattern
Posted
by serhio
on Stack Overflow
See other posts from Stack Overflow
or by serhio
Published on 2010-06-09T10:10:28Z
Indexed on
2010/06/09
10:12 UTC
Read the original article
Hit count: 285
In a project I have the following relation between BO and GUI
By e.g. G
could represent a graphic with time lines, C
a TimeLine curve, P
- points of that curve and T
the time that represents each point.
Each GUI object is associated with the BO corresponding object.
When T
changes GUI P
captures the Changed
event and changes its location.
So, when G should be modified, it modifies internally its objects and as result T changes, P moves and the GuiG visually changes, everything is OK.
But there is an inconvenient of this architecture... BO should not be recreated, because this will breack the link between BO and GUIO.
In particular, GUI P should always have the same reference of T.
If in a business logic I do by e.g. P1.T = new T(this.T + 10)
GUI_P1 will not move anymore, because it wait an event from the reference of former P1.T object, that does not belongs to P1 anymore.
So the solution was to always modify the existing objects, not to recreate it. But here is an other inconvenient: performance.
Say I have a ready newC
object that should replace the older one. Instead of doing G1.C = newC
I should do foreach T in foreach P in C replace with T from P from newC.
Is there an other more optimal way to do it?
© Stack Overflow or respective owner