Clean Architecture(MVVM)
Tags: android, architecture, mobile, design
Published: 2022-06-29 20:52:05

There has always been a discussion about which Android architectural pattern to use. You had the impression that something was wrong with the way things were set up from the beginning. Many people then experienced difficulty with architecture in general as a result of this.
However, writing applications in a clean manner has been discussed for a while. 
Understanding the concept behind the Clean architecture and why it's a good solution for the majority of issues we encounter today as programmers is very instructive because it can be used in any application and platform, not just Android.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/euwdw38uqlk9hwb0aycs.png)

Like other software design philosophies, clean architecture seeks to offer a practical method for creating high-quality code that performs better, is simpler to change, and has fewer dependencies.
The rings up top stand for the various software tiers in your app. Two important considerations must be kept in mind before continuing:

The most concrete ring is on the outside, and the most abstract ring is in the middle. The Abstraction Principle states that implementation details should be in the outer rings while business logic should be in the inner rings.
Another principle of Clean Architecture is the Dependency Rule. According to this rule, each circle can only rely on the inner circle that is closest to it, allowing the architecture to work.

###MVVM
A software design framework called Model-View-ViewModel (MVVM) distinguishes between program logic and user interface elements. In 2005, it was unveiled by John Gossman and Ken Cooper, two well-known Microsoft architects. In addition, MVVM is also referred to as a model-view-binder. The MVVM design pattern, like many others, aids in code organization and program module separation, enabling quicker and simpler code development, updating, and reuse. Windows and web graphics presentation software frequently use this design. The MVVM design is used by the Windows Presentation Foundation (WPF), which utilizes Microsoft's.NET platform. Silverlight, a multimedia plug-in that runs on the internet and is similar to Microsoft's WPF, also uses MVVM.

Using MVVM, your view—that is, your activity and fragments—is separated from your business logic. MVVM is adequate for small projects, but as your codebase gets bigger, your viewmodels start to bloat, and it gets difficult to divide responsibilities. In these situations, MVVM with Clean Architecture is a good option. It goes a step further in clearly defining the roles in your code base. Your app's actions have abstracted logic that makes them unintelligible. The Model-View-Presenter (MVP) architecture and Clean Architecture can now work together. As a result, we're choosing MVVM over MVP because Android Architecture Components already comes with a built-in ViewModel class, eliminating the need for an MVVM framework.

###The Advantage of Clean Architecture
- Compared to MVVM standard, code is simpler to test.
- Perfectly designed separation (the most important benefit).
- User-friendly package structure.
- It's simple to keep the project going.
- New features can be added by your team even faster.

###Disadvantages of Clean Architecture
- The learning curve is somewhat acute. Learning how all levels interact may take some time, especially if you're coming from architectures like simple MVVM or MVP.
- It has a lot more extra classes than is necessary, making it unsuitable for applications with simple requirements.

###Layers of MVVM  
Different people have different ideas about how many levels Clean Architecture should have. The design does not specify separate layers but instead lays the groundwork. The idea is that you can change the number of layers based on your requirements. Here, we'll use five to keep things succinct; take a look at them.

1. Presentation: This is a layer that interacts with the (UI)user interface.
2. Domain: The app’s business logic is stored here.
3. Use cases: Interactors are another name for them.
4. Data: All data sources are defined in a broad sense.
5. Framework: implements interfaces with the Android SDK as well as co
ncrete data layer implementations.