Mobile Architecture
A Word About Mobile App Architecture
Not All Architectures Are the Same
Choosing the right architecture is crucial in mobile app development, as it significantly impacts the app’s testability, scalability, and maintainability. Here’s a comparison of some common architectural patterns:
Model-View-Controller (MVC): This traditional pattern divides the application into three components — Model, View, and Controller. While it’s straightforward, MVC is often not easily testable because the Controller can become a catch-all for logic, making unit testing complex and cumbersome.
Model-View-Presenter (MVP): MVP separates the Presenter from the View, enhancing testability by allowing developers to test the Presenter independently of the View. However, it is not inherently reactive, lacking built-in support for real-time data updates and reactive programming paradigms.
Model-View-ViewModel (MVVM): MVVM introduces the ViewModel, which acts as an intermediary between the Model and the View. This architecture supports testability and reactivity, enabling automatic UI updates when the underlying data changes through data binding. MVVM employs unidirectional data flow, but it doesn’t utilize an immutable intent channel. This means that while data flows in one direction — from the Model to the ViewModel to the View — the state can still be mutable, which can complicate state management and debugging.
Model-View-Intent (MVI): MVI addresses the shortcomings of previous patterns by incorporating testability, reactivity, and immutable state. It uses unidirectional data flow and an immutable intent channel, making state management more predictable. Changes in the state are modeled as immutable data objects, which simplifies tracking state changes over time and enhances debugging capabilities.
Understanding these differences helps developers select an architecture that aligns with their app’s complexity and future scalability needs.
Android
In the early days of Android development, there was a notable lack of guidance on app architecture. Without established best practices, developers resorted to their own methodologies, leading to a fragmented landscape of languages, tools, and design principles. This inconsistency resulted in many poorly designed apps populating the Play Store. Unfortunately, users often blamed Android itself, remarking that “Android sucks,” rather than recognizing the individual app shortcomings. Thankfully, Google now provides clear guidelines and best practices, helping developers create robust, consistent, and high-quality Android applications.
Learn More:
iOS
Initially, Apple advocated for the Model-View-Controller (MVC) pattern, which proved insufficient for complex applications. Many developers shifted to their own versions of Model-View-ViewModel (MVVM). However, with the introduction of new tools like Swift, SwiftUI, structured concurrency, Combine, and SwiftData, uncertainty has grown around the proper way to architect apps today. The recent addition of SwiftData exacerbates this confusion, as it doesn’t integrate well with MVVM. Apple now has an opportunity to provide the developer community with clear, cohesive architectural guidance that leverages the latest technologies — Swift, SwiftUI, structured concurrency, SwiftData, SwiftCharts, and Swift Testing.
Without this guidance, developers are left to guess how their architectures will align with future advancements in the Apple ecosystem. It’s crucial for Apple to define best practices to ensure the development of robust and maintainable iOS applications moving forward.
Why This Matters: An Example
Consider two iOS experts with differing views on using ViewModels:
Mohammad Azam
iOS expert and educator, advises against using a ViewModel.
iOS expert and Stanford instructor, consistently uses a ViewModel, adhering to the MVVM pattern.
Who’s right? If you’re using SwiftData, Azam’s approach is advantageous because SwiftData doesn’t work well with MVVM. Adhering to Azam’s guidance makes transitioning to SwiftData seamless. On the other hand, if you’ve followed Hegarty’s MVVM approach, integrating SwiftData becomes challenging.
In retrospect, it seemed negligent for Google/Android not to provide solid architectural advice in the past, and we’re now witnessing a similar situation with Apple/iOS. Without insight into Apple’s roadmap, how can developers make informed, long-term architectural decisions?
By understanding the nuances of different architectural patterns and staying informed about platform developments, developers can make better choices that will stand the test of time.
It’s essential for platform providers like Apple and Google to offer clear architectural guidelines to support the developer community in building robust and future-proof applications.