Patrón de diseño MVC para el desarrollo de aplicaciones de Android mediante el uso de fragmentos como vistas y actividad como controlador

I was recently reading Fragments( haven't used this in my app though) and learnt that it can be used in phones app development.

I am thinking about using Fragments to implement MVC(model-view-controller) design pattern. Many argue that android development complies with MVC by default . But i do see Activities much like Views and there's definite lack of a controller when another activity is being/due to be launched. So i am thinking of using "Fragments" as "Views" con un solo "Actividad" as "Controlador" and swap/add/remove the fragments as and when needed.

So my basic approach is like this.

1) The user interacts with the user interface (Fragments).

2) The controller (Activity) handles the event from the Fragments and passes it to a model(Backendthread / Service).

3) Model(Backendthread / Service) notifies the controller of models state change.

4) The controller (Activity) notifes the UserInterface(Fragments) which inturn notifies the User.

does my approach is rite or an unnecessary overhead or my perception about fragments is wrong?

Por favor, aclarame.

preguntado el 30 de enero de 12 a las 19:01

I would like to see an example of your code when you will have something working -

1 Respuestas

IMHO, fragments are the controller. The fragment's basket of widgets represents the view. Activities are an orchestration layer, determining what fragments (and their widgets) are needed in a given circumstance (e.g., one on a phone, two on a tablet) but otherwise having limited business logic.

That being said, Android and patterns like MVC don't necessarily go together. I don't think that Google's intention was to create a pure MVC framework.

Respondido el 31 de enero de 12 a las 01:01

+1 for an iOS developer fragments make more sense because they are more like ViewControllers. But Activity is something different... - Alex Bush

Agreed. I found more explanation on this topic here stackoverflow.com/questions/6245722/android-design-patterns - manjusg

Thanks for this answer Mark. You definitly convinced me that my colleagues, with an iOS background, were on the right track. It's a pity there isn't a solid Android software design tutorial emphasizing this practice. - Snicolas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.