What we have learned?

We have learned a lot concerning building a well-ordered and organized application that is reusable and flexible using the MVVM architecture. But apart from the architecture itself, we have learned a couple of valuable things along the way, which are mostly Jetpack components.

Let’s highlight them.

  • Pagination: In this lesson, we saw how pagination helps load a large dataset by dividing it into smaller chunks, thus making a better use of system resources, including the bandwidth.

  • Room: We harnessed the power of the Room library for SQLite mapping by using annotations to write fewer lines of code to persist data locally for offline view, thanks to its easy integration with LiveData to return queries directly. We also looked at its subcomponents: Entity, DAO, and Database, which have highly used annotations to generate code in the background automatically.

  • ViewModel: ViewModel is the most critical component of an application because it’s the one that efficiently supports data for the UI components. It manages and handles UI-related data and is also lifecycle-aware to allow data to survive configuration changes, making it a mandatory component for best practice in software design.

  • Navigation Component: We learned how to implement the navigation framework to manage navigations and complexities that come with handling fragment transactions within the application, which includes navigation across, back, and into the application where we looked at its three key parts.

    • Navgraph holds XML-related information in one central location, which are different destinations within our application.

    • We learned that the Navhost fragment is an empty container that displays a destination from our navigation graph.

    • NavController helps in swap different destinations in the navhost.

  • ViewBinding: We learned how using ViewBinding can easily simplify how our code interacts with the views and how it easily generates the binding classes for each XML to replace the findViewById.

  • Error handling: We also saw a couple of ways to handle errors and exceptions. For example, we can deal with API failures by using the try and catch mechanism to detect server errors and no internet connection errors by notifying the user using pop-ups.

  • Constraint layout: We learned how to design layouts using constraint layouts. We can even use it to design more complex layouts, which are responsive and flexible because we don’t need to have different layouts overlapping on top of each other.

The above is just a summary of the main concepts we’ve learned about Jetpack components and the MVVM architecture. There are many other things we’ve learned from this course that aren’t listed, so keep practicing and progressing.

Pros of MVVM architecture

  • Easy maintainability: Clean separation of concerns makes it easy to go to specific parts of the code and make changes without affecting other parts of the code.

  • Easy to test: With pieces of code and dependencies being granular and implemented in excellent ways, it’s much easier to write unit tests, especially when testing the ViewModel to ensure everything works correctly even when things change during maintenance.

  • Easy extensibility: With the open-closed principle being emphasized throughout MVVM architecture, we have a better chance of reusing and extending our code without affecting other components directly.

  • Abstraction: With the abstraction of the view, we can reduce the amount of the business logic in the code behind hence decoupling the presentation layer and the business logic.

Cons of MVVM architecture

  • For simple applications with simple UIs, MVVM can be an overkill.

  • It’s complex to debug when we have complex data bindings.

  • It increases the amount of classes and components in our application.

Staying motivated

  • Programming has a very steep learning curve, whether self-taught or in a learning institution. To be able to be good at it, we must practice consistently every day, and in this lesson, we share a few tips that could further our understanding of the subject. With pieces of code being the granular and excellent implementation of dependencies, it is a lot easier to write unit tests, especially when testing the ViewModel to ensure everything works correctly even when things change in maintenance.

Building projects

Get hands-on with 1200+ tech skills courses.