What Is the Best Architecture for Android Apps?

Sdílet
Vložit
  • čas přidán 12. 07. 2022
  • In this video I'll ask one of the most commonly asked questions I get. Which architectural design pattern is the right for your app?
    ⭐ Get certificates for your future job
    ⭐ Save countless hours of time
    ⭐ 100% money back guarantee for 30 days
    ⭐ Become a professional Android developer now:
    pl-coding.com/premium-courses...
    💻 Let me personally review your code and provide individual feedback, so it won't backfire and cost you a fortune in future:
    elopage.com/s/philipplackner/...
    Subscribe to my FREE newsletter for regular Android, Kotlin & Architecture advice!
    pl-coding.com/newsletter
    Join this channel to get access to perks:
    / @philipplackner
    Join my Discord server:
    / discord
    Regular programming advice on my Instagram page: / _philipplackner_
    Checkout my GitHub: github.com/philipplackner
    You like my free content? Here you can buy me a coffee:
    www.buymeacoffee.com/philippl...

Komentáře • 99

  • @haykmkrtchyan7093
    @haykmkrtchyan7093 Před rokem +9

    MVP vs MVC.
    MVP - In android the view and presenter use interfaces to talk with each other. It's based on callbacks. The view triggeres a function from the presenter interface. Presenter implementation changes the model, gets the result back, and triggers view interface function. The view itself implements that.
    ========> =======>
    View Presenter Model

  • @IronGuy21
    @IronGuy21 Před rokem +3

    Lol. Just today i've started choosing architecture and project pattern and you publishing this video. Amazing. Thank you so much. I've seen video about MVVM from you a couple days ago actually, and this is a great addition to it.

  • @illusion9423
    @illusion9423 Před rokem +34

    I want to say.
    I've recently started to learn android and I think your presence and quality of your videos really makes this community.
    Your videos are detailed and they're great for learning from and you talk about all the relevant aspects of android and kotlin

  • @shaiquekhan1185
    @shaiquekhan1185 Před rokem +70

    MVI doesn't cause whole UI to be updated with each state change. Each composable function keeps track of the arguments passed to them so when you call copy on the state. Only the Composables with changed arguments will get recomposed, not the whole UI.

    • @PhilippLackner
      @PhilippLackner  Před rokem +47

      Speaking of compose, yes. Speaking of XML, it will always trigger the single flow collector which will re-compute all the UI logic.
      With compose I like MVI much more than with XML.

    • @shaiquekhan1185
      @shaiquekhan1185 Před rokem +2

      @@PhilippLackner yeah true that. Do you have any reference for handling race conditions in MVI? I have implemented MVI in a some of my projects and I had no idea about this disadvantage 🥲 now I wonder if it might break prod and will be really hard to find out

    • @PhilippLackner
      @PhilippLackner  Před rokem +21

      @@shaiquekhan1185 could be an idea for a video. All in all, make sure to use StateFlows and use flow.update {} to assign a new value instead of state.value = state.value.copy() directly

    • @ubersticks
      @ubersticks Před rokem +13

      @@PhilippLackner This is an important point - it seems to tilt the scale more towards MVI for Compose projects.

    • @webdrizzled
      @webdrizzled Před rokem +1

      I had the same doubt @Shaique Khan, Thanks for mentioning inside comments

  • @kenali4612
    @kenali4612 Před rokem

    Been waiting on this one !!

  • @nipunshah1373
    @nipunshah1373 Před rokem +1

    Amazing gist on various architecture options available for Mobile Development.
    As per my understanding just making flutter analogy for aforementioned videos :
    MVVM => Provider/Riverpod (ie Stacked Archi)
    MVI => BLOC
    MVC => GETX
    Above analogy is just in my opinion for flutter dev to map the knowledge share in the above video during flutter development !

  • @ClowneryCity
    @ClowneryCity Před 7 měsíci

    Thanks Philipp, this is well explained, you're a good teacher.💪

  • @webdrizzled
    @webdrizzled Před rokem

    Thanks bro. You are always helpful

  • @TheBlackManMythLegend
    @TheBlackManMythLegend Před rokem +5

    What I like about the videos of this awesome creator is that it's really good code and it's better than hello word. It's full of good practices. It's excellent for preparing for interviews( in my opinion) . It also increased my interest again for Android . ( as a 5 years experience android developer which means nothing if I don't push myself to learn new stuff or don't work in big teams in challenging projects, will start my first big team fintech job in august... So I am in the process to learn really good practice and that channel and his Github in my humble opinion are the go to place for me at the moment ) Very professional.

  • @EricLouisYoung
    @EricLouisYoung Před rokem

    I'm a backend dev getting up to speed on android. I do CQRS on the backend with Elixir. The pattern is so good that I'll be doing it in android. Seems very close to what you're calling MVI... intents = (C)ommands, and the (Q) (reading state) is merely the view subscriptions to the live data that gets updated as a result of successful Commands.

  • @prageeth4855
    @prageeth4855 Před rokem

    Woohoo 🎉 right on time!!

  • @mattgraves3709
    @mattgraves3709 Před rokem +5

    Kind of depends on a lot of factors, But if you build it correctly, each module and or component can use its own architecture, giving each team autonomy over their own architecture.

  • @GN9K71
    @GN9K71 Před rokem +2

    Very nice video! I want to ask something, should I combine both MVC and MVVM tohether, for example: I have a viewmodel class that has a StateFlow reference and I need to update some UI state based on the values emited from the flow, so I want to extract the collect logic in a seraprate Controller class, and pass the viewmodel to controller, or better create a ViewModelGetter - interface that will be inherited from the Activity/Fragment, and will provide the viewmodel. Than the viewmodel will be obtained by ViewModelGetter interface?

  • @go_better
    @go_better Před rokem +1

    Thanks for the video. I will surely check your videos about the subjects, just at the moment I don't understand what are ViewModels, Fragments, Content providers and Broadcast recievers for. It feels like it's unnecessary concepts. I don't get their benefits. But once again, I'm going to do my research.

  • @vengateshm2122
    @vengateshm2122 Před rokem

    Thank You Phillip.

  • @CharfaouiYounes
    @CharfaouiYounes Před rokem +4

    I think that any developer should learn about all of this architecture and get comfortable with them so that if we work on a project that uses MVP (Legacy Project), we can work effectively.
    And when working on greenfield projects, we can use the appropriate and better architecture that suits the app well.

  • @apoorvgupta2511
    @apoorvgupta2511 Před rokem

    That green light in the background sets the mood

  • @haykmkrtchyan7093
    @haykmkrtchyan7093 Před rokem

    Philipp can u make a video about MVI using the data classes? I've done that using only sealed classes))

  • @lukaslechner
    @lukaslechner Před rokem +6

    08:35 Regarding race conditions with StateFlows & copy - If you perform the .copy() _within_ the update{} lambda, then it should be thread-safe, right?

  • @whitebl4ckk
    @whitebl4ckk Před rokem

    Great video as always

    • @PhilippLackner
      @PhilippLackner  Před rokem +5

      For most projects it's too much imo. As I said at the end, learn about the core principles behind every architecture and then apply these principles and call it whatever you want

  • @TGDEVABHAi
    @TGDEVABHAi Před 3 měsíci

    Well explain

  • @Alchemist10241
    @Alchemist10241 Před rokem +1

    MVI plus a little bit MVVM is the best architecture. MVI fits very well with clean architecture.

    • @PhilippLackner
      @PhilippLackner  Před rokem +3

      I like mvi for compose projects, but not much for xml

  • @electromagneticbytes
    @electromagneticbytes Před 11 měsíci +1

    R.I.P MVVM..etc. after arrival of Jetpack compose 😅

  • @saurabhyadav-sz9rx
    @saurabhyadav-sz9rx Před rokem

    In my firm, we use clean-MVVM architecture.

  • @siddhantsolanki3933
    @siddhantsolanki3933 Před rokem

    Hey Can you please make a video on how to read and understand an existing Android Huge Codebase?

  • @CavernaMadridista-os9zn
    @CavernaMadridista-os9zn Před 11 měsíci

    A video to watch 2 times before an interview

  • @matthiaskerat351
    @matthiaskerat351 Před rokem +1

    Doesnt belong business logic to the model and not the viewmodel in mvvm per definition?

  • @yohankumar2441
    @yohankumar2441 Před rokem

    Hey i am making an app for image detection and store the data in a database. Few questions:
    1)I am unable to get updated location from fusedlocationproviderAPI after calling updates regularly
    2) which database is better NoSQL or SQL?

  • @DiegoNovati1
    @DiegoNovati1 Před rokem +10

    In the MVC architecture unfortunately the Controller knows the View (findById is just an example: it is used in the controller to change the View) and vice versa. It's the simples architecture to learn, but due tio the lack of separations on concerns it doesn't scale well in big projects.

    • @Berryss
      @Berryss Před rokem

      When I used mvc long time ago, the Controller never knew the view. Since the view changed using Callbacks from the controller. So the controller just knew an interface of the view, but not the actual view nor what views to change

    • @koczmen22
      @koczmen22 Před rokem

      @@Berryss That sounds like MVP. On both Android and iOS, MVC usually means no architecture at all. All stuff goes into the Activity or UIViewController.

    • @GN9K71
      @GN9K71 Před rokem

      Should Controller has to know anything about ViewModel?

    • @DiegoNovati1
      @DiegoNovati1 Před rokem

      @@GN9K71 MVC is Model/View/Controller so there is no ViewModel (ViewModel is in MVVM = Model/View/ViewModel)

  • @rhen4610
    @rhen4610 Před rokem

    Heyy I have a question regarding viewmodel states, are data classes better than sealed classes when youre using them for your project's UI states? I noticed you switched from sealed class to data class on the note app and crypto app clean architecture video.

    • @PhilippLackner
      @PhilippLackner  Před rokem +3

      They both have completely different purposes, I definitely did not use them for a whole screen's UI state

  • @shalomogbeche5680
    @shalomogbeche5680 Před rokem

    Very knowledgeable

  • @thiagosouza8931
    @thiagosouza8931 Před rokem +1

    Isn't MVI more than states and events? Like reducer, middleware, state machine and everything? What you said sounds just like MVVM 🤔

  • @breensrobert
    @breensrobert Před rokem

    well explained

  • @nieqingls2931
    @nieqingls2931 Před 7 měsíci

    in compose + flow , how to control webview to reload ?

  • @sandeep_khariwal8137
    @sandeep_khariwal8137 Před rokem

    Should we learn all these model views or become good in one???

  • @mustafaammar551
    @mustafaammar551 Před rokem

    you are the best
    thank you

  • @wojtekw9008
    @wojtekw9008 Před rokem +41

    Hey Philipp,
    Can you show difference's between MVI and MVVM on real code example? :)
    Btw i really love your content ❤️

  • @moldovanpeter5123
    @moldovanpeter5123 Před rokem

    What about MVVM + ReduxKotlin for state management? I know that there some who are working this way on Diamond Client Projects.

  • @bhoomivaghasiya2794
    @bhoomivaghasiya2794 Před 6 měsíci

    Which Architectural pattern do you prefer for Large-scale Jetpack Compose apps? MVVM or MVI?

  • @HenriqueRocha
    @HenriqueRocha Před rokem +1

    Stopped watching when he said that Activities and Fragments are represented by the V in MV* patterns. I don't know why so many people get this wrong.

  • @rontarrant
    @rontarrant Před měsícem

    I've been experimenting with MIM (Monkey in the Middle), a looser take on MVVM in which the logic goes where it needs to be for clarity.

  • @bbk8550
    @bbk8550 Před rokem

    Are 'Android Architecture Component' and 'Clean Architecture' the same? If difference between let me know?
    Thank you...

  • @boukarradhmoez99
    @boukarradhmoez99 Před rokem +1

    @Philipp so what is the difference between these architectures and the clean architecture ?

    • @Frozen_Priest
      @Frozen_Priest Před rokem +2

      Clean architecture is for a whole application, mvx are presentation layer only. Your app can be clean while using any of them

  • @elqd91
    @elqd91 Před rokem

    you’ve said that in MVI, a screen has one state object. following this, how would you handle having multiple API calls on a single screen? let’s say you have 2 cards, one that shows the weather and one that shows user info. would you still use one state object and how would this look? or one for each card (API call)?

    • @ohefny
      @ohefny Před rokem

      So for me when it comes to single screen state it always mean that this states are related in some way inside the screen, so yes if you have two related parts in the screen that needs to be updated from 2 apis you'd probably combine them in a single state and whenever updates comes in you update the respected value in the state.
      But designing how the screen parts relate to each other makes things easier usually.
      So if multiple parts in the same screen are somehow indpendent those can ve separated to different fragments in the same screen with each fragment contining its state.
      If fragment spiliting is not an option you can also go with multiple viewmodels in the same fragment each one of them is related to specific portion.
      So it depends on the usecase actually.

  • @baljeetsandhu8718
    @baljeetsandhu8718 Před rokem

    Hehe morning dose of Android... Thanks

  • @yangyun6221
    @yangyun6221 Před rokem

    MVC: controller can updates View!

  • @sebastianseno9285
    @sebastianseno9285 Před rokem +1

    MVVM is best for me

  • @SiamakAshrafi
    @SiamakAshrafi Před rokem

    multi-module clean arch MVI is the best ... simple

  • @FemiOkedey
    @FemiOkedey Před rokem +2

    I prefer to use MVI for personal projects because it's easier to understand and explain especially with Compose.
    But I prefer MVVM professionally.

  • @theophilus494
    @theophilus494 Před rokem +1

    thank you Phillip. i just want to ask how do schedule your studying time.. like how do you allocate time to learning.. i use MVVM android dev since it's google's recommendation

    • @PhilippLackner
      @PhilippLackner  Před rokem +1

      I learn most of my stuff either by creating videos or by working on actual projects and researching my issues. Both belongs to my work

  • @k40ol
    @k40ol Před rokem +1

    Good video!
    Would prefer more:
    - Diagrams, showing these in action.
    - Less talking, more whiteboard / abstract concept demonstration.

  • @alanesaugarciagutierrez6025

    Hi Phillip what about VIPER?

    • @argahutama
      @argahutama Před rokem

      In my opinion, VIPER is the next level of MVP (Clean arch version of MVP). I think that's not common in Android. MVVM and MVI are the perfect arch pattern for Android atm.

  • @erfansn869
    @erfansn869 Před rokem

    MVI + MVVM + CLEAN = Android recommended architecture

  • @RiccardoGabellone
    @RiccardoGabellone Před rokem

    💪🏻

  • @kyleolson8977
    @kyleolson8977 Před rokem

    I cannot agree with the "More Vulnerable to Race Conditions", at least for the reasons you're saying. If your data in MVVM or in MVI could be touched on another thread while you are touching it, you're doing something wrong. Any data which could be touched by multiple threads must be protected. "If you don't practice thread safety it's not thread safe" is not a bug if the thread safety is fairly straightforward as it is here.
    At best, it's "less likely for mistake to matter". It's possible or even likely the copy is so quick compared to UI operations using data that if you are dealing with unprotected data in both models the MVVM ui is more likely to create an inconsistent state. This would be much more of a literal race condition.

  • @freedomchuks
    @freedomchuks Před rokem

    Update from the state flow is thread safe hence you wouldn't get the race condition

    • @PhilippLackner
      @PhilippLackner  Před rokem +1

      Not, if you update it using copy() without flow.update

    • @freedomchuks
      @freedomchuks Před rokem

      @@PhilippLackner we are saying the same thing I hadn't gotten the part when you talked about the update extension so I wrote the comments

  • @favour2871
    @favour2871 Před rokem

    goat

  • @user-rr2db1vu3z
    @user-rr2db1vu3z Před rokem

    👍

  • @alonshlider4881
    @alonshlider4881 Před rokem +2

    MVI can be implemented with a sealed class representing the UI state which prevents the race condition you were talking about because you set the value to a new one and not copying the old one

  • @CavernaMadridista-os9zn
    @CavernaMadridista-os9zn Před 11 měsíci

    even MBS got a shout out jajajajaja

  • @nikhilsingh-zs1ul
    @nikhilsingh-zs1ul Před rokem

    MVVM

  • @user-kh6rp6yx1j
    @user-kh6rp6yx1j Před 2 měsíci

    Hello

  • @parveshkhatri1027
    @parveshkhatri1027 Před rokem

    I'm learning android dev for a year and I don't like it. First, they don't give good documentation, I mean I can't go there and code something from reading there like creating a notification. Second, thay change things very quickly, codes from year-old tutorials can't be used today without modifications, which also they don't document that well.

  • @DiegoNovati1
    @DiegoNovati1 Před rokem +5

    Lot of mistakes in this video. the MVVM is not about states but it's about visibility and accessibility. In the MVVM the View knows and uses only the ViewModel, and the view models knows nothing about the View, infact it raises events that can be managed by any View listening for the events; the ViewModels knows and uses only the Model, but Model knows nothing about ViewModel because it notifies changes raising events for any ViewModel listening for the events. MVVM was created by John Gossman in 2005, and it's not related to Android at all.
    Another details: if you are using Compose, I suggest you to have 1 single state in the ViewModel (implemented as a read only Data Class) and each time you need to update it, change all the properies you need and then notifiy the change: the View will recompose itself in one go instead of recomposing itself by the number of properties you are changing.

  • @John-qt6qk
    @John-qt6qk Před rokem

    MVVM ALL THE WAY

  • @omarredani5580
    @omarredani5580 Před rokem +1

    It seems like you are taking Gym really seriously hhh

  • @yangyun6221
    @yangyun6221 Před rokem

    If MVVM, then what is Acitvity/Fragment's role in this architecture. I have to say Android is a mess.

  • @mouhamadbourouba5382
    @mouhamadbourouba5382 Před rokem +1

    MVI makes my life easier so I use it 🙂

  • @mymobile550
    @mymobile550 Před rokem

    😄

  • @misiu9049
    @misiu9049 Před rokem

    There is no the best architecture. Architecture is project specific !

  • @patrickrodriguez4683
    @patrickrodriguez4683 Před rokem

    MVVM is best for me