MVVM vs. MVI - Understand the Difference Once and for All

  Переглядів 21,642

Philipp Lackner

Philipp Lackner

19 днів тому

After this video you'll understand the Difference Once and for All - MVVM vs. MVI!
👉 Save your spot for the FREE workshop 'The Essentials of Industry-Scale Android Development - REVEALED' on April 27: pl-coding.com/android-workshop
💻 Let me be your mentor and become an industry-ready Android developer in 10 weeks:
pl-coding.com/drop-table-ment...
⭐ Courses with real-life practices
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:
pl-coding.com/premium-courses/
Get my FREE PDF about 20 things you should never do in Jetpack Compose:
pl-coding.com/jetpack-compose...
Regular programming advice on my Instagram page:
/ _philipplackner_
Join my Discord server:
/ discord

КОМЕНТАРІ: 110
@rychy7601
@rychy7601 17 днів тому
All this time using MVI thinking it was MVVM hahaha, thanks for the video!!!
@johnaqualls389
@johnaqualls389 9 днів тому
Same 😄
@george_sigalas
@george_sigalas 17 днів тому
I've used MVP, MVVM, and MVI professionally over the past 3 years. I personally tend towards using a mixture of MVVM and MVI. And there are a couple of reasons. - The MVVM pattern is just too good on a practical level. You don't have to worry about configuration changes, coroutine scopes, etc. It just works. - The MVI pattern is very good to reason about and Kotlin superpowers it. All in all the MVVM pattern solves many technical challenges of previous architectures, such as configuration changes, data access and DI. ViewModels in many cases are an extension of the actual View. Now, combine that with the simplicity of MVI and we have an amazing architecture pattern that is very easy to reason about.
@jam4l
@jam4l 17 днів тому
I have just found out that I have used MVI in my latest project (relatively a small project) with out me knowing anything about MVI 💀 this actually make me think that MAYBE the right architecture will naturally enforce it self into your project, without you thinking about it that match...
@pelealexandru
@pelealexandru 17 днів тому
you are not alone! i've also just realised i've implemented MVI to the bone! (thinking i'm doing plain MVVM)
@weaponx3373
@weaponx3373 16 днів тому
exactly, I didn't know this too. I just thought it is a different way of writing viewModel class. but know knowing the term it get clearer to me.
@user-ix5jb5jf6m
@user-ix5jb5jf6m 16 днів тому
the same)))
@blaupunkt1221
@blaupunkt1221 17 днів тому
Personally, I think its totally fine to use a mixture of both.
@tiltedbybox6118
@tiltedbybox6118 17 днів тому
Yeah for example if some of the MVVM states are dependent on one another, you can just group them in a MVI fashion. Maybe it has disadvantages, but it works and still keeps things relatively clean.
@Mike-er2ih
@Mike-er2ih 17 днів тому
Exactly what I'm doing. Works very good.
@jakosss
@jakosss 17 днів тому
Orbit mvi is the hybrid approach. Very simple and nice pattern
@cloakrabbit767
@cloakrabbit767 17 днів тому
Mvi is just more boilerplate
@philblandford5560
@philblandford5560 16 днів тому
I've always thought there are two aspects to MVI that don't necessarily need to belong together - a single state object, and a message queue with sealed classes. You can always use one without the other, depending on your requirements. Lots of methods in your VM? Use a message queue MVI style. Only one method? Probably not worth it. Likewise if a screen has lots of components that update frequently and independently of each other, maybe a single state object isn't best, but if it's fairly static, it may make more sense to use a single data class. I just mix and match MVVM and MVI according to what I need.
@DanielLuche
@DanielLuche 17 днів тому
Since 2022 I'm using MVI and I'm really enjoying this. Excellent video and explanation, everytime I see your videos the subject became clear for me. Thanks
@ibrahimaydn2030
@ibrahimaydn2030 17 днів тому
As an android developer, I watch every video with eagerness. 🤩
@illuminati786uuh
@illuminati786uuh 17 днів тому
Heyyy how are you ?
@ibrahimaydn2030
@ibrahimaydn2030 17 днів тому
@@illuminati786uuh good , know ı you ? 😄
@illuminati786uuh
@illuminati786uuh 17 днів тому
@@ibrahimaydn2030 Nahh you a stranger to me just asked it I mean their is allot going.
@user-pn7hx7wx2k
@user-pn7hx7wx2k 17 днів тому
I make a mixture of both, all my state are wrapped in data class and my methods remains in viewmodel, my ui receives a data class as state and callbacks from viewmodel, that's make more sense for me, to use the better of both worlds.
@PedroBarbosaRoman
@PedroBarbosaRoman 17 днів тому
I don't think that the difference lies in using using a ui state object instead of multiple states for each field, since we can have the same MVVM implementation but with an ui object instead of multiple mutable states for each fields. I think the difference is more on the "intent" part, which makes state management more manageable and predictable. For instance, when I was using Redux, a state management library for React, the intents would enable us to have an "history" of all the past uiStates and the actions that produces them, for debugging purposes or others, and that is really not possible in MVVM unless we track the changes in other ways. In MVI the foundation for that to be possible is already baked in by using the actions. By the way, in Redux we also had the concept of reducers, but I'm not sure if that is exclusive to MVI.
@grumpyshoe
@grumpyshoe 17 днів тому
A really nice explanation! Thanks for your effort Philipp! 👍
@emanuelemaso3061
@emanuelemaso3061 16 днів тому
The best comparison found out there! Cheers 👏
@Coldalecs
@Coldalecs 17 днів тому
Love it! keep up the good work! Very informative.
@lifebylazy
@lifebylazy 17 днів тому
You're the man phillip thank you!
@laujimmy9282
@laujimmy9282 13 днів тому
Thanks for your content, finally I get to fully understand the difference between MVVM and MVI. It seems mixing them is the best way to go, as long as it makes the code clean and readable.
@leonardocvaleriano
@leonardocvaleriano 15 днів тому
Whata job!! Thank you for sharing your knowledge!
@ngapps
@ngapps 17 днів тому
This shortcut with KFunction instead of multiple lambdas is smths crazy beatuful! This is what I was missing in my MVI implementation
@nikwintren
@nikwintren 17 днів тому
You can check out my reply regarding another solution. I'm not selling something, I just want some genuine input :P
@vegadhardik
@vegadhardik 17 днів тому
Very informative video and great explanation, I love each of your videos. Thanks for sharing.
@weaponx3373
@weaponx3373 16 днів тому
I didn't know the difference in between mvvm and mvi . mvi is much more readable. knowing the difference will help me learning mvi faster. thanks for the video
@solokiller5883
@solokiller5883 17 днів тому
Great video, I really like mvi pattern a lot it makes the code less complex and more readable
@Alchemist10241
@Alchemist10241 16 днів тому
11:14 for navigation events I used to create another UI event class but with this approach I don't need to.
@dusilva3796
@dusilva3796 17 днів тому
I aways used MVVM, however looking at MVI it seems very nice.
@arielapp9469
@arielapp9469 17 днів тому
do you guys remember when the common architecture was MVC? how about relax about what is the best architecture, and do what you're most comfortable with?
@ayeshdon
@ayeshdon 17 днів тому
Thanks @philipp Since this both very similar we can you both in single project. thats my option here.
@user-ge3yl6nu5o
@user-ge3yl6nu5o 15 днів тому
Personally, I use MVI. I see issues with MVVM when complexity increases. For now I combine MVI with having Events (intent), Actions, Reducers, UiState and SideEffects. Because of this, my viewmodels are very simple, even the most complex ones don't reach more than 200 lines. Also, the whole codebase is very testable. It respects single responsibility and after getting used to it, making changes becomes very simple. It is maybe important to say that now, the most difficult part is to define Events, Actions and the UiState properly. They are all sealed classes and I think this is the best way to represent business logic
@DiabloZq
@DiabloZq 16 днів тому
Thank you!
@sparshchadha5469
@sparshchadha5469 17 днів тому
Hey, please create a video on different flavours of app that companies usually create and how we can write functions in gradle files
@coldwised
@coldwised 12 днів тому
If you have a large viewmodels and problems with navigation, you should try the Decompose library
@pelealexandru
@pelealexandru 17 днів тому
your videos are the best.
@vitalijuskolinko9011
@vitalijuskolinko9011 15 днів тому
I've tried MVi and I liked it :) Will use it as default for the next projects )
@tuanphanvan5169
@tuanphanvan5169 8 днів тому
Thank for your video 👍
@gekylafas
@gekylafas 17 днів тому
Having a single onAction() which handles all user events seems a bit unnatural for me. It also tends towards large viewmodels. On the other hand, having a single state class is nice.
@josephofem5448
@josephofem5448 12 днів тому
I mostly use MVI but of late, I sort of use a mix of both as I find it more convenient.
@gleb-dev
@gleb-dev 16 днів тому
Probably, another advantage of MVI is a more loose dependency between the view and the ViewModel. The view just sends events to the ViewModel and the ViewModel itself decides what to do with it. Whereas in MVVM the view holds direct references to callbacks, and any change in the methods can potentially break the build. In modern IDEs it's not a problem, but for Kotlin Multiplatform linting doesn't work
@forbiddenbox
@forbiddenbox 15 днів тому
could you make another app tutorial? your plalist is very outdated and I find it hard to learn so this is the best channel
@ayeshdon
@ayeshdon 17 днів тому
@philipp shall we have playlist on android AR and Android automotive.
@baijusharma6027
@baijusharma6027 15 днів тому
Any plans to start a series on AOSP, as there are lots of things to cover and online no tutorial available.
@Ayor88
@Ayor88 17 днів тому
I'm a bit confused about navcontroller and navigation, since in your example you pass it to the composable and in the official documentaiton, it's recommanded to not pass it and just expose navigation action. That would be nice to have more info on this topic (I know you have many videos about navigation in compose, but I encountered many case uncovered by these)
@zappy__idk-vw8eg
@zappy__idk-vw8eg 17 днів тому
For most React Devs learning Android + Jetpack Compose, go with MVI as it's very similar to Redux
@skarloti
@skarloti 16 днів тому
When we use KMP, we have a solution with expect (Common) and actual MVVM deployments on different platforms. So MVI becomes redundant.
@PhilippLackner
@PhilippLackner 16 днів тому
Why does it become redundant? Usually, you'd want to share the ViewModel and maybe even the UI
@SamyakKumar-ck8se
@SamyakKumar-ck8se 16 днів тому
of course mvvm, because d LEGEND Philip uses it most of the time
@mateusznepath3344
@mateusznepath3344 17 днів тому
16:07 oh wow didn't know about the snapshotFlow. But wouldn't it trigger extra recomposition?
@szpitor
@szpitor 15 днів тому
I think as most says in here use mvvm with mvi I would prefer. End of the day make the code read able that is the most important goal.
@robchr
@robchr 17 днів тому
In my experience, MVVM is more flexible for having multiple concurrently running asynchronous operations that update the UiState. MVI only allows for a single asynchronous operation at a time which can be easier write tests for.
@walrider7374
@walrider7374 17 днів тому
I think I understand what you mean (I'm a Junior), can you help me? What you are saying is that (as for an example) if my UI has 2 buttons that ultimately make a HTTP call that can potentially take 1 or 2 seconds, and both are pressed simultaniously something may go wrong? Like if I press button A and ActionA is dispatched and before it finishes I press ActionB it will somehow cancel ActionA?
@Rajmanov
@Rajmanov 17 днів тому
​@@walrider7374 no, you can queue it or handle it separately through middleware or a similar mechanism to ensure both actions are addressed.
@k4ba
@k4ba 17 днів тому
@@Rajmanov Then @robchr point is invalidad? Or this queueing and middleware thing just makes it less efficient than just using MVVM? To my understanding, it's safe to combine both MVVM and MVI dependending on the requirements of each specific UI/Screen
@veluchamykarthik107
@veluchamykarthik107 17 днів тому
Could you make video about clean architecture
@devatrii
@devatrii 17 днів тому
lol i didn't even knew that i was using MVI
@SoftSkilsDevs
@SoftSkilsDevs 11 днів тому
😂😂😂 you're not alone
@jackeblan
@jackeblan 16 днів тому
It seems that I will move to MVI since it might fix the problem of my composables having alot of callbacks to viewmodel. A problem raised by state hoisting. Having alot of parameters to a function defies clean code.
@nikwintren
@nikwintren 17 днів тому
I am, apparently, using MVI / MVVM - neither, both, hybrid... and by the sound of what you're saying it bridges both MVVM and MVI eliminating the all/most bad parts. - I have an object "FeatureModels" that houses my supporting actors; `data class State()` | `sealed interface Event{}` | `interface Actions {}` - My ViewModel extends StateEventViewModel (or a subset for smaller screens State / Event) which exposes a single state (StateFlow) , a single "event buss" through a Channel and it also implements the Actions interface. - My Composable ScreenWrapper ("Route") holds a composable ("Screen") which takes always only two arguments: State and Actions. Route have access to the navController, NavBackStackEntry as parameters. It gets the ViewModel from hilt, collects State from ViewModel and holds the screen: FeatureScreen(state = state, actions = viewModel). Then the Route does `viewModel.collectEvents { event -> when (event) { ... } }` which mostly just handles navigation or platform interactions. - Also 1: The ViewModel have some nice `update { state -> state.copy(x ) ...) }` and `sendEvent(Event.GoToDetails("itemID"))` utility functions - Also 2: I have some extension functions that handles observing state and events using lifecycle etc. for the Route - Also 3: In the Feature Models object I have another object that holds nice to have preview states and actions: Preview {val emptyState: State get() = ..., val actions get() = ... } To me this is flawless, and I love it, but what is it? MVVM or MVI?
@georgikopchev1739
@georgikopchev1739 14 днів тому
Based on the video, should be MVI
@est4058
@est4058 13 днів тому
In last 5 years, iOS, Flutter and now Android - all MVI. Just found it more predictable in development, maintenance and testing. Also should to note that SwiftUI, Flutter and Compose - all perfectly fit to MVI
@yewo.m
@yewo.m 9 днів тому
MVI reminds me of Elm and Redux/useReducer in React (I'm a web dev learning mobile, BTW)
@yossimaskin1393
@yossimaskin1393 17 днів тому
Is there a reason why you used mutableStateOf and not MutableStateFlow? I remember you had a video in which you preffered the StateFlow approach. Is that changed over the time? I'm just curious
@clementjoymasinamela4244
@clementjoymasinamela4244 16 днів тому
It depends, if you wanna map, filter etc then use MutableStateFlow but if not you can use mutableStateOf
@-sb9nb
@-sb9nb 16 днів тому
In MVI , do we need to create some state or sharedFlow for oneTime events like toasts or snackBar . And how to handle error- in the main UiState or maybe create another state for error ?
@josephmalachosky7141
@josephmalachosky7141 11 днів тому
Would using state.copy() to update values of the UI state data class from the ViewModel indicate I'm mixing practices of MVVM and MVI? I'm invoking my VM from my View directly, but I am holding reference to a single UI state data class as MutableStateFlow(MyUiState())
@Guilo583
@Guilo583 17 днів тому
i am a little bit confused. Some you use the event class in your mvvm project is that not similar to mvi?
@bogdan.801
@bogdan.801 17 днів тому
And what if I use the single screen state like in MVI but all the actions of the screen are done with a separate method like in MVVM? Is it wrong?
@ztzmtv7069
@ztzmtv7069 16 днів тому
I use MVI in complex screens but when the screen is simple, MVVM is better in my opinion
@walrider7374
@walrider7374 17 днів тому
MVI reminds me on Flutter BLOC pattern
@TheShadowvaultAwaits
@TheShadowvaultAwaits 17 днів тому
Most mvi tutorials I've seen except yours, have a store and a reducer. Can you elaborate on that?
@PhilippLackner
@PhilippLackner 17 днів тому
Store = the combination of state class and VM Reducer = onAction function
@aditya3n
@aditya3n 9 днів тому
@@PhilippLackner possible to share your source code of this MVVM and MVI? I'm trying to implement MVI on my KMP project..
@cloakrabbit767
@cloakrabbit767 17 днів тому
I don't see the benefit of MVI. Would someone explain? To me it seems it's just more boilerplate code
@DeveloperDikshitaPatel
@DeveloperDikshitaPatel 12 годин тому
How to get details of the workshop? As i am late to book me slot
@ManuelSilverioCoder
@ManuelSilverioCoder 16 днів тому
As usual you managed to explained this better than anyone out there. Great video!!! I always use MVVM so it is the one that makes sense to me, but I can see the value in knowing both specially when you need to work with an existing app that someone else developed using MVI.
@PhilippLackner
@PhilippLackner 16 днів тому
Thank you 🙌🙌
@graart6076
@graart6076 16 днів тому
i like to use MVVM but with states-classes🙂
@sabbib007madness
@sabbib007madness 17 днів тому
so what is the pattern which has a state class with "Callbacks", is that MVIVM? I'm starting to miss the vanilla days of android where android team told everyone to figure out their own architecture. seem like we've gone away from the original definition of MVVM which was data changes are a stream of data emitted by VM and were starting to label everything like a religion 😮‍💨
@processorman2858
@processorman2858 15 днів тому
Sir I am unable to access the internet on my android emulator
@abr464
@abr464 15 днів тому
Same here, using MVI thinking it was MVVM lol
@androidkotlin-6234
@androidkotlin-6234 16 днів тому
MVI is really better then MVVM, because I have only one source of truth for my UI - data class UiState()
@alexmercerind
@alexmercerind 14 днів тому
Can we say MVI is built on top of MVVM? No?
@ishubhamsingh
@ishubhamsingh 17 днів тому
So it seems i have been using MVI without knowing its MVI since quite a while 😂
@tashi7160
@tashi7160 16 днів тому
sometime I feel like we android developers are stuck in M** patterns world.
@David-zb8br
@David-zb8br 17 днів тому
so i been using mvi this whole time thinking it was mvvm 😅
@YvoneKoge
@YvoneKoge 15 днів тому
flutter😁
@SriNagaPhaniSarmaMokkapati
@SriNagaPhaniSarmaMokkapati 17 днів тому
first view
@mikec4220
@mikec4220 17 днів тому
What is the point of acknowledging this? I keep seeing these types of comments but don't understand why people do it. Can you shed some light?
@illuminati786uuh
@illuminati786uuh 17 днів тому
​​@@mikec4220what's the point of wasting your time by replying to these comments.
@mikec4220
@mikec4220 17 днів тому
@@illuminati786uuh same as you spending your time replying to mine ;). P.S. I'm naturally interested in behavioural patterns and had my reasons for that comment.
@illuminati786uuh
@illuminati786uuh 17 днів тому
@@mikec4220 lol I knew you will say this 😂
@Rajmanov
@Rajmanov 17 днів тому
MVI and MVVM are overrated, keep it simple and readble is better with observable patterns and MVC
@Salehalanazi-7
@Salehalanazi-7 17 днів тому
MVI is a mess in large projects :)
@robertfontaine3650
@robertfontaine3650 17 днів тому
Talk really fast and show some code but don't focus on the appropriate use of each pattern after 7 minutes of yapping at twice the rate that anyone could ever listen to. wtaf? I don't need to see your face or hear you talk about irrelevant details that have nothing to do with the topic.
@pisoga1991
@pisoga1991 16 днів тому
Wait until you guys see a VIPER in an Android project.
@foryoutube5118
@foryoutube5118 17 днів тому
Plz make some good project on android. Philip Lackner
This Is My FAVORITE Error Handling Class
28:57
Philipp Lackner
Переглядів 21 тис.
Этого От Него Никто Не Ожидал 😂
00:19
Глеб Рандалайнен
Переглядів 4,8 млн
skibidi toilet 73 (part 2)
04:15
DaFuq!?Boom!
Переглядів 19 млн
ALL MAJOR AI + Robotics  NEWS April 2024 (All AI and Robotics Updates)
2:51:23
The Only .NET Scheduler You Should Be Using!
16:38
Nick Chapsas
Переглядів 32 тис.
Разбираем основы Kafka и RabbitMQ
26:54
Digital train | Alex Babin
Переглядів 6 тис.
ViewModels & Configuration Changes - Android Basics 2023
18:46
Philipp Lackner
Переглядів 90 тис.
Big Tech AI Is A Lie
16:56
Tina Huang
Переглядів 56 тис.
98% Cloud Cost Saved By Writing Our Own Database
21:45
ThePrimeTime
Переглядів 206 тис.
Should You Use a Navigation Library in Jetpack Compose?
11:27
Philipp Lackner
Переглядів 24 тис.
Build ENTIRE Frontends With ONE Prompt - OpenUI Tutorial
8:59
Matthew Berman
Переглядів 25 тис.
iPhone 15 Precision Finding | Find Your Friends | Apple
2:52
Клавиатура vs геймпад vs руль
0:47
Balance
Переглядів 542 тис.
Що покаже Apple, гнучкі айфони та Windows переходить на ARM
17:49
Ноталка Шелягіна
Переглядів 60 тис.
Тестируем Gravis Ultrasound... ну почти.
48:18
Дмитрий Бачило
Переглядів 30 тис.
Broken Flex Repair #technology #mobilerepair
0:55
ideal institute aligarh
Переглядів 16 млн
Result of the portable iPhone electrical machine #hacks
1:01
KevKevKiwi
Переглядів 7 млн
Компьютер подписчику
0:40
Miracle
Переглядів 207 тис.