MVVM :
MVVM definition MVVM is short for model-view-viewModel. Is a software architecture design pattern developed by Ken Cooper and Ted Peters, architects of Microsoft WPF and Silverlight, as an event-driven programming approach to simplifying user interfaces. Published by John Gossman (also WPF and Silverlight architect) on his blog in 2005. Model-view-viewmodel.
MVVM should be changed to M-VM-V to make it easier to understand intuitively. The View-Model acts as the glue layer that binds the View View to the data Model.
MVVM is not a pure front-end architectural pattern. It is suitable for all applications that contain a GUI (Graphical User Interface) (including the backend).
MVVM can actually be subdivided into four layers of M-C-VM-V architecture.
Understanding of the above M-C-VM-V layer:
L M(ODEL) layer: define data structure and build abstract model of application.
Landing page M layer example:
class LoginActivity : BaseActivity() { private var viewModel: LoginViewModel? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = DataBindingUtil.setContentView<ActivityLoginBinding>(this, R.layout.activity_login) viewModel = ViewModelProvider(this).get(LoginViewModel::class.java) binding.viewModel = viewModel viewModel? .status? .observe(this, Observer<StatusBean> { t -> when (t? .status) { LoginViewModel.go_main -> MainActivity.start(this@LoginActivity) } }) } }Copy the code