banner



How To Design Android App Architecture

10 things every Android app developer should know about Architecture

Ashesh Bharadwaj

Photo by gdtography from Pexels

Architecture in object-oriented words for a monolithic app can be simply described as the placement of classes in the system and how they communicate. We draw an overview of roles and responsibilities of these classes while grouping them.

Here are a few things which may help us understand about architecture:

1. Architecture is language and platform agnostic: Architecture is based on the principles of programming. These guiding principles, be it SOLID principle or design/architectural patterns are stable and the knowledge can be applied across language and platforms. Investing the time in learning architecture pays off well. It not only help us design better architecture but also improve our coding skills.

2. The confusion about MVP/MVVM: The responsibility of MVP (Model-View-Presenter)/MVVM (Model-View-ViewModel) is to separate UI from the code. We use Presenter/ViewModel to strip any logical code from the View (Activity/Fragment). This separation involves VP/VVM leaving us with Model(M) whose job is to provide data to the Presenter/ViewModel.

What I Usually see is Presenter and ViewModel are implemented diligently with interfaces and observers but beyond that it's chaos. I think this can be blamed on taking VP/VVM for the whole architecture of an app and not putting effort to shape the Model(M). MVP/MVVM plays a crucial role as an architectural pattern but the architecture of an app goes beyond UI separation.

3. Architecture is important but not essential: Learning Architecture comes at a later stage in the evolution of an Android app developer. One of the reason is that our apps can excel functionally even without architecture so why spend extra time? How would we convince our boss/client that the extra time we spend may not have any immediate benefit?

It's only after a few version we realize the mess we are in but then it's too late. As we keep getting in the same mess, again and again, we start to understand the essentiality of architecture.

4. Architecture improves changeability: Architecture wouldn't matter much if there was only one version to be released of an app. In fact this is the approach many of us take, while developing app, which is shortsighted.

If I have to point out the biggest benefit of having a proper architecture that would be the ease of modification and its effectiveness.

It's true that we can't foresee everything that the app may become in future but a good architecture has enough flexibility to adjust to those unknown future changes.

5. Architecture doesn't require special knowledge: For a good programmer designing architecture comes naturally. This is somewhat a repeat of point #1 but it's important so I thought to twist it a little and present again 😃

Dagger/RxJava or any other tool require us to learn things specific to them. In the case of architecture it's just the programming principles and guidelines. The better we become at coding the better we are able to visualize the architecture of an app.

6. Architecture requires discipline and patience: Architecture is like a tree. We can't get fruits the day we plant it. It takes time and effort to design an architecture and it's an ongoing process. Every change in the app would require a thoughtful decision before the implementation.

The major damage comes to an app architecture when we start taking shortcuts. The promises we make to ourselves (to clean the code later) only to be broken again and again.

We need to understand what we are getting into otherwise it would be a great start only to lose later. Architecture is our lifelong commitment to an app.

7. Google Architecture components: In 2017 Google introduced Architecture Components. Architecture components are not there just to shift the mess from Activity/Fragment to ViewModel. These "Architecture" components are there to facilitate us in designing the architecture of the app. These components make it easy to implement the architecture which otherwise would have been a difficult task.

For example, LiveData makes it easy to observe changes in data that too respecting the lifecycle of Activity/Fragment. One may find ViewModel a way to survive configuration change but its real implication is to help us separate UI from the logic.

8. We don't have to go all the way to become a Software Architect: Every software architect is a developer but not every developer is an architect. In a large organization there are designated software architects. For them, it's essential to have deep knowledge of various architectural patterns and how they work.

As a developer, it helps to have an understanding of architecture so that we can make sense of the abstractions implemented. This becomes more important if we are working freelance or in a startup with limited resource. In such a case, it would suffice to have a basic knowledge of architecture.

There are many simple patterns and principles we can adopt to create a decent architecture for our app without going too deep into architecture world.

9. Benefits of architecture: As mentioned earlier one of the advantages is changeability. Adding new features and modifications become easy and quick if the components are properly separated and communicate in an organized manner. This separation leads to many other advantages like testability where we can easily test components in isolation.

10. Where to start? Architecture is everywhere, embedded systems, web applications, enterprise software, mobiles apps etc. Each of them requires a different type of architecture. Unless we want to be software architect we have to be selective of what we begin with.

A good read to understand the need of architecture and its implementation would be Clean Architecture by Robert C. Martin (aka Uncle Bob) and a little deep is Domain-Driven Design: Tackling Complexity in the Heart of Software by Eric Evans.

Google provides guide to app architecture with dependency flowing in one direction but that's a bare minimum. Once you have grasped that you may want to implement a layered architecture pattern guided by Clean Architecture. This approach is easy and would suit most of the apps. I have created a sample app following these principles. Here is the Github repo of the sample app.

If you are new to programming, I would suggest starting with SOLID principles as they would make you architecture ready :)

You may also want to read my 5 article series Android app architecture by example where I discuss the architecture in detail.

Thanks for reading this article. You can connect with me on LinkedIn and Twitter

If you like this article, please recommend it by hitting the clap icon as many times you wish 👏 Let's enable each other with the power of knowledge.

How To Design Android App Architecture

Source: https://proandroiddev.com/10-things-every-android-app-developer-should-know-about-architecture-75ffc37df556

Posted by: reedthowite1944.blogspot.com

0 Response to "How To Design Android App Architecture"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel