浅谈MVVM

几个框架名称MVC/MVP/MVVM

MVC:
Model, View, Control

MVP:
Model, View, Presenter

MVVM:
Model, View, ViewModel

在这之间,先前谈的介面就是View,它包含了:Activity, fragment, View, Adapter 等等

在最新的架构,Google 提出了ViewModel(https://developer.android.com/topic/libraries/architecture/viewmodel),它是做为View/Model之间的交换、逻辑处理 (https://developer.android.com/jetpack/guide)
主要的目的跟MVP接近,但奂成了DataBinding 来作业

官方也提出了几点重要的参考:
Avoid designating your app's entry points—such as activities, services, and broadcast receivers—as sources of data.

Create well-defined boundaries of responsibility between various modules of your app.

Expose as little as possible from each module.

Consider how to make each module testable in isolation.

Focus on the unique core of your app so it stands out from other apps.

Persist as much relevant and fresh data as possible.

Assign one data source to be the single source of truth.

MVVM 另外有几个优点:资料趋动、下层元件不需了解上层元件(不必知道View是谁)、职责清楚

官方的介绍完整易读,十分推荐


<<:  Day15-Vue SFC 单一元件档

>>:  【Day30】参赛感言

Day 24:605. Can Place Flowers

今日题目 题目连结:605. Can Place Flowers 题目主题:Array, Greed...

修改 DOM 元素样式

在网页的互动效果中,常常是当使用者符合了某个条件时,画面上的元素产生令人惊喜的变化,这些变化可简单可...

第13章:分析、储存与存取系统日志介绍(二)

前言 继上次介绍了系统日志与相关的介绍後,接下来介绍该如何使用journalctl将日志档案永久的储...

[Day 08] 从 tensorflow.keras 开始的 VGG Net 生活 (第一季)

-1. 序 OK,资料分析做完了, 现在要进入演算法的部分, 我们未来几天将从经典卷积神经网路架构中...

Day18-React起步

在我们进入React的环节之前,需要先理解一些会很常听到、看到的关键字 CSR(SPA) SSR S...