Maximizing the Leverage of Architecture in Android

Maximizing the Leverage of Architecture in Android

Making the most out of the architecture components that complement your app and team.

Picking the right architecture pattern can be a debated topic. There are plenty of popular options like MVP, MVVM, Clean Architecture, etc.

The general role of architecture is to do several things

  • Establish a common & reusable structure
  • Establish flow of data & control
  • Encourage separation of concern

Let’s assume we make the bold claim that architecture doesn’t matter. Okay, what are we left with then to talk about? Architecture Components

Architecture Components

These are the building blocks and patterns that compliment the codebase. Architecture components are the real heroes that deserve a lot of attention that architecture is hogging.

Architecture components are also the implementation of the promises made by the architecture.

Image for post

MVVM is composed of 3 architecture components

Repository Component Example

Let’s look at an example of a repository that retrieves app details and how it highlights the importance of design and implementation.

data class AppDetail(
        val id: Long,
        val name: String,
        val description: String,
        val publisher: Publisher
    )

    interface ResultCallback<T> {
        fun onSuccess(result: T)
        fun onError(exception: Exception)
    }

    class AppRepository(private val api: AppApi) {

        fun getAppById(id: Long, resultCallback: ResultCallback<AppDetail>): AppDetail { /*...*/ }

        fun getAppsByPublisher(
            publisherId: Long,
            resultCallback: ResultCallback<List<AppDetail>>
        ) { /*...*/ }

    }

This implementation has the following qualities

  • AppRepository holds a reference to the consumer
  • The repository handles threading internally.
  • The repository result is communicated through ResultCallback

The code works but could we do better? Yes, yes we can.

interface AppRepository {
        suspend fun getAppById(id: Long): AppDetail
        suspend fun getAppsByPublisher(publisherId: Long): List<AppDetail>
    }

    class AppApiRepository(private val api: AppApi) : AppRepository {
        override suspend fun getAppById(id: Long): AppDetail { /*...*/ }
        override suspend fun getAppsByPublisher(publisherId: Long): List<AppDetail> { /*...*/ }
    }

    // Potential class
    // class AppDatabaseRepository(private val appDAO: AppDAO) : AppRepository {
    //     override suspend fun getAppById(id: Long): AppDetail { /*...*/ }
    //     override suspend fun getAppsByPublisher(publisherId: Long): List<AppDetail> { /*...*/ }
    // }

clean-architecture androiddev software-architecture android-app-development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

Top Android App Development Companies | Hire Android App Developers USA | TopDevelopers.Co

Are you looking for an apt android app development firm for your business requirement? TopDevelopers.co has simplified the whole process of [hiring android app developers in the...

Top Android App Development Company in USA

AppClues Infotech is a top Mobile App Development Company in USA building high-quality Android, iOS, and Native apps for Startups, SMBs, & Enterprises. Contact us now!

Android Mobile App Development Company in USA

AppClues Infotech is the best mobile app development company in New York that offers custom mobile app development & design services for Android and iOS.

Best Android App Development Services Provider in USA

AppClues Infotech is a top Mobile App Development Company in USA building high-quality Android, iOS, and Native apps for Startups, SMBs, & Enterprises. Contact us now!