What Drives Modern Android Architecture? From MVC to MVX and Router‑Based Decoupling
This article examines the evolution of Android architectural patterns—from MVC, MVP, and MVVM to Flutter‑derived frameworks and Android Architecture Components—explaining their layering, communication mechanisms, and how router‑based decoupling can achieve fully modular mobile applications.
I am an Android developer sharing my perspective on various architectural patterns and summarizing the core of mobile architecture; the differences between iOS and Android architectures are minimal.
Discussing mobile architecture may seem exaggerated because mobile projects are often small, but applying solid architectural principles can improve code elegance and reduce coupling.
Since Android’s inception, architecture has evolved many times: from the original MVC to MVP, then to the less common Flutter (derived from React Native) and Google’s AAC/MVVM. Although the names change, the underlying ideas remain similar.
MVC, MVP, MVVM, Flutter, AAC
MVC MVP MVVM Flutter AAC
Among these, the MVX series (MVC, MVP, MVVM) share a common layering, while Flutter and AAC introduce different communication concepts.
Flutter (React‑Native derived)
Flutter here refers to a framework derived from React Native, not the popular UI toolkit. Its elements are View, Model, Store (handles Actions, similar to a Presenter), Dispatcher (routes Actions), and Action (events). Communication follows a router mechanism rather than direct object references.
Android Architecture Components (AAC)
Refer to the official documentation at developer.android.com . The AAC demo source shows a clear MVVM‑like structure where ViewModel resembles a Controller or Presenter.
Layered Architecture
Local architecture is layered: Data handling (Model), UI display (View), and business logic (X). This mirrors the classic separation of concerns.
Communication Mechanisms
Different modules share similar layer names but differ in communication:
Object‑based communication (e.g., MVC/AAC) where modules hold references to each other.
Interface‑based communication (e.g., MVP) where modules interact through defined interfaces.
Router‑based communication (e.g., Flutter) where a Dispatcher routes Actions between decoupled modules.
Router‑based communication resembles a network router: it receives multiple signals and distributes them to multiple receivers.
Code Examples
public class X implements Dispatcher.IReceiver{ Model model; public X() { model = new Model(); Dispatcher.getDispatcher().register(this); } public void clearX() { model = null; Dispatcher.getDispatcher().unregister(this); } @Override public void onReceive(Action action) { if(action.name.equals("login")) { model.postLogin((User) action.data, new Model.Callback() { @Override public void onResponse(int result) { if(result == 1) { // 登录成功 Dispatcher.getDispatcher().sendEvent(new Action("login-success", null)); } else { // 登录失败 Dispatcher.getDispatcher().sendEvent(new Action("login-failed", null)); } } }); } } }
public class Action<T> { public String name; // e.g., "login" public T data; // e.g., username, password public Action(String name, T data) { this.name = name; this.data = data; } }
public class Dispatcher { private static Dispatcher dispatcher = new Dispatcher(); private List<IReceiver> receivers = new ArrayList<>(); private Dispatcher(){} public static Dispatcher getDispatcher() { return dispatcher; } public void register(IReceiver receiver) { if (receivers.contains(receiver)) { throw new IllegalStateException("receiver has been registerd yet!"); } else { receivers.add(receiver); } } public void unregister(IReceiver receiver) { if (receivers.contains(receiver)) { receivers.remove(receiver); } } public void sendEvent(Action action) { if (action != null && action.name != null && action.name.length() > 0) { for (IReceiver r : receivers) { if (r != null) { r.onReceive(action); } } } } public interface IReceiver { void onReceive(Action action); } }
These examples show that modules act both as message senders and receivers, with all communication routed through the Dispatcher, achieving complete decoupling.
We can further optimize the router by adding grouping and tagging mechanisms, similar to Alibaba’s ARouter, to improve efficiency and robustness.
Key Takeaways
Mobile architecture can be described as MVX (Model‑View‑X), where X may be Presenter, ViewModel, or Controller.
Communication mechanisms fall into three categories: object holding (least decoupled), interface holding (moderately decoupled), and router‑based (fully decoupled).
Router‑based designs, while powerful, require careful design for performance and maintainability.
Understanding these core ideas makes it easier to grasp new frameworks as they emerge.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
