views:

43

answers:

1

Class1 creates and calls a method in Class2. Class2's method updates it progress to an event handler in Class1. But now Class2's method needs to call a method in class3. How can class3 update it's method's progress to class1? Do I need to daisy chain the events and delegates all the way down each level?

(I'm using the MVC pattern, The UI class calls the controller class which calls a worker class. I need 2 progress bars updated in the UI class. A main progress bar updated as controller methods finish and a sub progress bar that upgrades as a loop processes in the worker class. The controller runs in a background process so the UI doesn't hang.)

+2  A: 

The worker class reports to the controller which then notifies the UI of the progress. The worker class and UI shouldn't and won't know each other. Just create another event pair between worker class and controller (this is called event bubbling or event chaining, thanks @Abel).

Femaref
So you suggest I create one event/delegate pair where the worker class updates the controller and a second event delegate pair where that worker update is further sent from the controller to the UI?
hi tech credo
@high tech credo: Yes, I believe that's what Femaref means. It's what's sometimes referred to as *event bubbling*, or more accurately, *event chaining*.
Abel
@Abel: Ok but I don't have just one worker. Theres worker 1 through 20. The user may run any one of these workers. There is only one progress bar for the workers. So I'll have to add 1 event handler to the controller and subscribe each of the workers event/delegate to it. Is that right?
hi tech credo
yes, this is right. Just do that at the creation of the workers (I guess they are generated in the controller with a loop, so it shouldn't be much of a hassle)
Femaref
@Everyone: Thankyou for the replies. ( I love how friendly this site is :D )
hi tech credo