gpt4 book ai didi

android - Android 是否支持 MVC(Model View Controller)结构?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:07:08 24 4
gpt4 key购买 nike

我想知道,Android是否支持MVC(Model View Controller)结构?如果支持的话1.什么是 Controller ?2.什么是模型?和3.什么是 View ?

请清除我。我对此有些困惑。

最佳答案

Which design patterns are used on Android?

Model-View-Control works fine

The actual Activity class doesn't extend android's View class, but it does, however, handle displaying a window to the user and also handle the events of that window (onCreate, onPause etc).

This means, that when you are using a MVC pattern, your controller will actually be a pseudo View-Controller. Since it is handling displaying a window to the user, with the additional view components you have added to it with setContentView, and also handling events for atleast the various activity life cycle events.

In MVC, the controller is supposed to be the main entry point. Which is a bit debatable if this is the case when applying it to android development, since the activity is the natural entry point of most applications.

因此,android 中的伪 MVC:

模型 = 具有主要业务逻辑的实体或类

View = 布局、资源和小部件,如 EditText

Controller = Activity , 适配器

enter image description here

关于android - Android 是否支持 MVC(Model View Controller)结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12139469/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com