I have a controller that receives an event with some data. As a part of the processing this s new data it needs to modify a collection in another controller. Is it a bad idea to inject a controller into another controller to modify this collection?
Asked
Active
Viewed 173 times
0
-
I voted to close as "Bad ideas", "good ideas", and "Best practices" are often subjective topics. As such I don't believe this can be answered definitively. – JeffryHouser Aug 23 '11 at 16:22
-
I completely disagree. Here is my reasoning. If something like this leads to a memory leak, performance issue, or could cause an issue in the future then by answering you will have prevented a non-subjective problem – asawilliams Aug 23 '11 at 16:37
-
There are plenty of "best practices" that can be fine in one situation and lead to memory leaks, performance issues, and maintenance nightmares in different contexts. There is no "black and white" answer. – JeffryHouser Aug 23 '11 at 17:50
2 Answers
1
I don't really understand what you mean by "a collection in another controller", but IMHO your collection should be in the model. Your first controller modifies the collection in the model which dispatches an event caught by the second controller.

Kodiak
- 5,978
- 17
- 35
-
Sorry, I should have mentioned that I am using swiz. The collection that I am modifying is then injected into views. – asawilliams Aug 23 '11 at 16:31
-
@asawilliams Actually the model should notify the view, which then in turn can notify the controller('s). Have a look at this [MVC diagram](http://upload.wikimedia.org/wikipedia/commons/b/b5/ModelViewControllerDiagram2.svg). – RIAstar Aug 23 '11 at 16:50
-
@RIAstar, that is not how this framework works. check out [swiz](http://swizframework.jira.com/wiki/display/SWIZ/Home) for more information. – asawilliams Aug 23 '11 at 17:17
-
@Riastar where does that diagram come from? In my experience, a big purpose of using an MVC approach is to keep the model and view separate and reusable. Adding a model dependency into a view strikes me as off. – JeffryHouser Aug 23 '11 at 17:49
-
@Flextras Comes from [Wikipedia](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller). I would think it has been checked a zillion times. Keep in mind that most ActionScript 'MVC' frameworks actually use the [mediator pattern](http://disanji.net/iOS_Doc/documentation/Cocoa/Conceptual/CocoaFundamentals/Art/cocoa_mvc.gif). – RIAstar Aug 23 '11 at 18:05
-
@asawilliams If your framework doesn't allow a class to dispatch events and another one to react to that, ditch it. Gotta say: I find that hard to believe. – RIAstar Aug 23 '11 at 18:07
-
@RIAstar, I didnt say that and I pointed you to the frameworks documentation. – asawilliams Aug 23 '11 at 19:59
-
@asawillams My apologies, that came out a bit harsh. I just never saw the point of using a framework on top of Flex, which already is a framework. And definitely if it prevents you from quickly implementing a simple solution as Kodiak's. That being said, I did skim through the docs and found a Mediator pattern, but no built-in controller. As such I see nothing holding you back from doing it as Kodiak suggests. – RIAstar Aug 24 '11 at 08:26
0
I'm not too familiar with Swiz, however in other frameworks if you needed to have another 'controller' do something after a result, it would dispatch an event that the second controller is listening for giving it the data it needs.

J_A_X
- 12,857
- 1
- 25
- 31