What is difference between mvvm with clean architecture and mvvm without clean architecture in Android?

Viewed 9286

I'm learning about MVVM and Clean Architecture. Then I found some articles present about MVVM + Clean Architecture, but I still didn't get it about the difference between mvvm with clean architecture and mvvm without clean architecture. Any summary about these stuff? Thank you.

5 Answers

Clean architecture aims to separate the layers. Business Layer, Data Layer and Presentation Layer will be separate applications. Therefore you will increase the reusability for each one of them. MVVM as design pattern should be implemented in the Presentation Layer. Presentation Layer will interact with Business Layer (or Domain Layer) and the Business Layer will use Data Layer for sharing data.

MVVM is just part of the clean architecture in the presentation layer. It just a set of rules on how to display the data from UseCase.

One of the benefits of using clean architecture is we can change our design pattern in presentation layer without changing domain layer or use case.

So for example, if we're using let say MVI and then changing to MVVM, it can be done smoothly with ease.. :)

MVVM is just a technique to manage the View layer of whatever architecture you're using.

Clean Architecture is a way of organizing communication between layers. They aren't mutually exclusive

The Layers of MVVM with Clean Architecture The code is divided into three separate layers:

  • Presentation Layer
  • Domain Layer
  • Data Layer

Presentation Layer
Is here, where the logic related with views and animations happens. It uses Model-View-ViewModel ( MVVM), but you can use any other pattern like MVC or MVP

As I understand:

MVVM without clean architecture:

______________________________________________

UI
- - - - - - - - - - - - - - - - - - - - - - - 

Presenter/ViewModel        (Business Logic)
______________________________________________

Repository

DataSource
______________________________________________

MVVM with Clean Architecture:

______________________________________________

UI
                                                Presentation Layer
Presenter/ViewModel        
______________________________________________

UseCases + Entity          (Business Logic)    Domain/Business Layer
______________________________________________

Repository
                                                Data Layer
DataSource
______________________________________________

Clean Architecture is a set of rules and principles that helps you maintain and architect a software system. While MVVM is a Design Pattern (similarly like other ones MVP, MVC) that is originated from Clean Architecture.

As Clean Architecture strongly recommends to separate each layer UI, Controllers, Use-cases & Entities, MVVM does the same job as it separates each of them in:

  • UI -> View
  • Controllers -> ViewModel
  • Use-cases/Entities/APIs/Local/Repos/etc. -> Model

That's what I understood. Hope this helps :)

Related