tags:

views:

445

answers:

4

In an application I'm working on I've implemented a MVC pattern to use different views for displaying parts of a UI. In an overall UI there's an entry box, in which the user can give commands or queries. The idea is that this entry box generates a few basic events, like "ValidEntry", "InvalidEntry" and "EmptyEntry". Each one of the controller parts should respond to these events. I do not want every controller that is subscribed to the ValidEntry event to respond, only the one that is active.

I could add an "if" to every eventhandler that checks if "this.IsActive" is true and update that on every switch of views. Or add different events for all different controllers. Any better ideas on this problem?

+1  A: 

Assuming only 1 controller is active at once, how about having some sort of controller manager class, with a SetActiveController method. The manager would subscribe to the UI events and call the approproate method on the currently active controller.

ng5000
Or do all controller's need to receive the event as well as just the active one? I.e. all receive, but only one responds?
ng5000
Only one controller will be active at a time. I like the idea of a manager. I'm figuring out how to implement it...
Sorskoot
+1  A: 

Not sure if the different "views" are all visible and focus changes or if they're hidden when they're not Active but having your "one controller to control them all" keep track of the visibility or focus and subscribe/unsubscribe the given sub-controllers to the events is probably how I'd implement it. With interfaces/abstract classes you should be able do it generically.

Mark G
+1  A: 

For events like the ValidEntry where you want only a single controller to respond to, the simplest way is to "downgrade" it into a delegate and assign it to the active controller's handler whenever it receives focus.

Of course a manager keeping track of visibility and subscription will definitely give better structure when this simple requirement gets complex. But for now it's an overkill :)

Heartless Angel
A: 

I just need to know, How i can implement th same kind of soln. in WEB. I want all the the controller parts should respond to these events