views:

158

answers:

4

I was a JaveEE developer. Recently I joined an Android development team. The structure of Android confused me. The MVC design pattern seems not suit for Android development. So what's is the design pattern principle for Android development? I means is there any hint about how to write a clean, easy reading and effective Android code.

A: 

this should help:

http://code.google.com/events/io/2010/sessions/android-ui-design-patterns.html

cheers

Marko
those are UI design patterns. That was not the question.
Janusz
sorry, I can't download the PDF file in that website.
Chris
oops, you are right, sorry...that's the dark side of stackoverflow voting system, sometimes you just want to win the points :)
Marko
+3  A: 

The actions, views and activies in Android are the baked in way of working with the Android UI and are an implementation of a model-view-viewmodel pattern, which is structurally similar (in the same family as) model view controller.

To the best of my knoweledge, there is no way to break out of this model. It can probably be done, but you would likely lose all the benefit that the existing model has, and have to rewrite your own UI layer to make it work.

You can find MVC in the followings:

  • You define your user interface in various XML files by resolution/hardware etc.
  • You define your resources in various XML files by locale etc.
  • You store data in SQLite or your custom data in /assets/ folder, read more about resources and assets
  • You extend clases like ListActivity, TabActivity and make use of the XML file by inflaters
  • You can create as many classes as you wish for your model, and have your own packages, that will act as a structure
  • A lot of Utils have been already written for you. DatabaseUtils, Html,

There is no single MVC Pattern you could obey to. MVC just states more or less that you don't should mingle data and view, so that e.g. views are responsible for holding data or classes which are processing data are directly affecting the view.

But nevertheless, the way Android deals with classes and resources, you're sometimes even forced to follow the MVC pattern. More complicated in my oppinion are the activites which are responsible sometimes for the view but nevertheless act as an controller in the same time.

If you define your views and layouts in the xml files, load your resources from the res folder, and if you avoid more or less to mingle this things in your code, then your anyway following a MVC pattern.

Pentium10
hmm...it is more code behind concept than mvc...becuase you have xml definitions of layouts(xml files), and you have 'code behind' code that work with these layouts..it is more tightly coupled than mvc, where views(xml layouts in this case) know nothing about controllers(code behind code here)..
Marko
The most problem in our Android project is the coupled. One class seems do everything for one module. I need a principle to decoupled it, just like MVC.
Chris
A: 

My impression is that android programming model has lots of similarity with MS WPF. XML layout definitions, code that is always bound to one of these definitions... So, if you are asking about design patterns because you want to improve your current or in development android projects, maybe you should look at WPF practices and patterns for improved architecture, like MVVM.

Check out these links:

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

there is small project that is already trying similar thing:

http://code.google.com/p/android-binding/

cheers

Marko
A: 

Android development is primarily GUI development, which like Swing/AWT in Java consists of lots of anonymous inner classes reacting to GUI events. Its one of the things that has really kept me away from doing a lot with Swing....but I have an Android phone, so I'm going to grit my teeth and just get over it, as many an Apple fanboy has said about the antenna problems. ;)

mezmo