0

I would like to implement the MVC pattern to an existing Flex project. I want to separate out the controllers and models from the views. They currently all live together in large mxml files.

My question is, should httpservice requests be in the model or the controller? What sort of advantages/disadvantages would there be to either?

Steven
  • 1,949
  • 2
  • 17
  • 30
  • Can I ask why you want to do it without a framework when there's already plenty of awesome ones out there and already have the code done for you? – J_A_X Jul 01 '11 at 20:10
  • @J_A_X You mean like the ones **[mentioned here?](http://stackoverflow.com/questions/37043/flex-mvc-frameworks)** – Robert Harvey Jul 01 '11 at 20:13
  • @J_A_X That's a reasonable question. I think it'd be a good way to learn, taking an existing project and refactoring it to a MVC pattern. If I were starting from the beginning on this project, I would definitely consider using a framework but I'd like to see what can be done without introducing a framework and overhauling everything just yet. – Steven Jul 01 '11 at 20:27
  • Adding a framework doesn't particularly mean 'overhauling everything'. You can add it in little by little. My biggest concern of not using a framework that's already been proven is that you're now starting to reinvent the wheel and possible take a lot of time to debug your code. Personally, I don't think it's possible to have a real MVC pattern (since everything is view based) without using one of these frameworks that does dependency injection and hierarchical contexts. Which again, you don't want to have to recode from scratch. – J_A_X Jul 01 '11 at 20:52
  • @J_A_X Well, I don't so much want to create a true MVC pattern as much as taking existing code and separating out the model, view and controller, particularly for organization purposes. Something along the lines of this: http://www.unitedmindset.com/jonbcampos/2009/08/18/flex-best-practices-models-views-and-controllers/ – Steven Jul 01 '11 at 21:06

3 Answers3

1

I normally try to abstract any service request into a Command call (execute, result, fault) which gets the service it needs to called injected in (which can be a good idea to abstract even more and be a service delegate).

There's a good example of how to use short lives command objects in Parsley's dev manual (one of the more popular frameworks).

J_A_X
  • 12,857
  • 1
  • 25
  • 31
0

I looked at httpservice, and it seems to me that, while the service itself might reside in a repository or Service Layer (between the controller and the model), using the service involves references to UI elements such as DataGrid. So the implementation of that service probably would occur in the controller, or even in a ViewModel object.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
0

I would rather approach the services as something totally different - an MVCS, not just MVC. You should check the Introduction to Flex Application's Architecture I wrote in my blog.

Vladimir Tsvetkov
  • 2,983
  • 3
  • 26
  • 36