简体   繁体   中英

Android mvvm - does every crud operation should have it own ViewModel?

Does every CRUD operation should have own ViewModel? For example, should I have separated classes for Insert,Delete,Update?

You should have a Data Access Object (DAO) for every Entity. There is no need for separate ViewModels for every CRUD operations.

One or multiple ViewModels can then use this DAO as needed. Look at this DAO for a reference. See how this repository and viewmodel work with it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM