0

It's my first real android application and i want to begin it using good design patterns because it will be a little big ,so i can manage my code easily . Can I User 3-tiers architecture and "MVC" together in Android ? I used it in ".net" and it was so good choice but i don't know if i can use it in android or not.

I checked this question but i still confused , i can't realize the difference between MVC and MVP , and i don't find any comment according to use n-tier with MVC or MVP to gether

Community
  • 1
  • 1
Asmaa Rashad
  • 593
  • 5
  • 28
  • 1
    Possible duplicate of [Android application architecture - what is the suggested model?](http://stackoverflow.com/questions/3320534/android-application-architecture-what-is-the-suggested-model) – Pooya Apr 03 '16 at 12:15
  • I read it now but i still confused , i can't realize the difference between MVC and MVP , and i don't find any comment according to use n-tier with MVC or MVP to gether – Asmaa Rashad Apr 03 '16 at 12:34
  • @cricket_007 [this](http://stackoverflow.com/questions/10739914/what-is-the-difference-between-3-tier-architecture-and-a-mvc) explains the difference between MVC and 3 tier – Asmaa Rashad Apr 03 '16 at 14:48

3 Answers3

2

There are many guides out there where people show usable architectures or worship one architecture as THE STANDARD, writing whole Books about old Methods applied to modern problems. In difference to these, this is only a rough answer:

Android encourages you to use MVC or some MVC Variant (MVP/MVVM/...) for the Activities/Fragments. You can apply the 3-Tier Architecture on the whole App.

Presentation Layer

The MVC or variant is applied to the Presentation Layer. Your Presenter/Controller handles your view, inflation and modification, ui control bindings like onclick events, maybe some effects that are bound to this view alone and so on.

Business Layer

Here is your business logic. Your workflows, processes, rules, ...

Data Layer

And data handling goes here.

The Others

It's a good start to keep things in these 3 Layers, for both maintainability and testing. This is the basic outline of my apps, both on Android or iOS but I'm not always pressing everything into these 3 Layers. For example Components for scanning Bluetooth devices, doing downloads in the Background (or other Background services and Tasks) or adding a Camera Preview with full set of controls. I keep those separate for reuse without the troubles of writing and importing a library.

makadev
  • 1,034
  • 15
  • 26
0

To generally answer the question, yes.

By definition of MVC (or MVP), there are three tiers (not linear, though, but in a triangle).

  1. Presentation (View)
  2. Logic layer (Controller / Presenter)
  3. Data layer (Model)

There is nothing stopping a true n-tier architecture in Android. For example, you could use XML SharedPreferences flat files or SQLite as persistence data layers, then the SqliteOpenHelper class as the next tier to read&write data, which in turn would be passed to an Adapter and displayed in some ListView.

Moving off the local filesystem, you use network requests to communicate with some remote API layer which communicates with its data storage layer.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 3 tier architecture is different . it may contains MVC in one of it's layers(presentation layer) ,i was also confused at first but after actual practice i realizes the difference totally.[this was my question](http://stackoverflow.com/questions/33321967/converting-mvc-ef-to-3-tiers-architecture-model/36352374#36352374) at the beginning of using 3-tier and MVC together but as ".Net" and i explained how i mixed them together in this question. – Asmaa Rashad Apr 03 '16 at 14:57
0

You can think that the Model and the View in MVC correspond to the Intermediate (business logic) and Presentation in 3-tier (3-layer if you prefer), respectively.

Assuming that your Model in the MVC include a data layer, then Model would correspond to both the Intermediate and Data access layer. I will call this Model1.

If you introduce the controller between this Model1 (Intermediate and Data access layer) and the View (Presentation) then you would have an MVC/3-tier architecture.

But if you prohibit the View to update the Model1, then you would have a 3-tier/MVC architecture, that is, an architecture where the view cannot update the model directly, as happens in 3-tier, and for this reason I put the name of 3-tier in front.

asam
  • 359
  • 3
  • 12