Forum Xamarin Xamarin.Forms

MVVM Really Necessary?

JesseLibertyJesseLiberty USInsider, University ✭✭✭

I'd like to start a (non-religious) discussion about whether the benefits of MVVM outweigh the hassle when your phone app is (mostly) just displaying data.

I recently worked on a project in which the user moved from page to page making selections and being shown either a new list of options or being shown data, but there was virtually no business logic involved; all the logic was on the server.

Putting everything in the VM became a royal pain because I had to manage navigation and alert boxes and I ended up using the message center extensively. I didn't reap the benefit of Unit Tests because, as noted, there was virtually no logic to test.

Do you resort to code behind in these cases, and if not, why not?

I know this raises hackles, but I'm not advocating either way; I'm just opening a discussion.

Thanks

Posts

  • LewisKLewisK USUniversity ✭✭
    edited December 2017

    You can just use it where it makes sense.

    Although if you have a large team it can be hard to enforce people not putting logic into the model. That can make it very tricky sometimes to distinguish what is stored/carried/etc locally instead of what is retrieved from the server and very quickly get out of hand.

  • JesseLibertyJesseLiberty USInsider, University ✭✭✭

    Yes, View and Model distinction is critical, it is the VM I'm questioning; and only when there is little or no biz. logic.

  • NashZhouNashZhou USMember ✭✭✭
    edited December 2017

    @JesseLiberty I would follow what @LewisK said. Are you a single developer? If you're the only developer maybe you don't have to worry about this kind of stuff.

    When you're in a larger team you'll need to get people on the same page. If I was working with you and I created all my non-UI related classes in the App.xaml.cs file you wouldn't like that now would you? You and every other Xamarin Forms developer would probably hate me. It's not a black or white issue, just use what makes sense.

    Maybe you need a ViewModel, maybe you don't. Structure is nice especially when you're working with others.

  • LewisKLewisK USUniversity ✭✭

    @JesseLiberty said:
    Yes, View and Model distinction is critical, it is the VM I'm questioning; and only when there is little or no biz. logic.

    Yes I know, what I was saying was @NashZhou stated more elegantly above.

  • NMackayNMackay GBInsider, University admin

    MVVM doesn't fit all scenarios.

    Like all patterns, you have to decide when it's of benefit.

    The pattern for example will allow you to switch from Forms XAML to XAML Standard painlessly if the app is well implemented (when xaml standard comes along).

    Using message center extensively suggests the pattern is been misused or your just running into MVVM scenarios where frameworks like Prism, MVVMLight, MVVMCross etc take over the heavy lifting.

    You can reinvent the wheel and write base classes or pick a framework that takes care of the navigation etc.

  • JesseLibertyJesseLiberty USInsider, University ✭✭✭

    @NMackay Talk with me about over-using message center. How will MVVMLight help me with that? I know that what i'm doing is ugly but don't yet see a good way around it.

    Your point about XAML Standard is very well taken.

  • NMackayNMackay GBInsider, University admin

    @JesseLiberty said:
    @NMackay Talk with me about over-using message center. How will MVVMLight help me with that? I know that what i'm doing is ugly but don't yet see a good way around it.

    Your point about XAML Standard is very well taken.

    I can't, I don't know your solution. With regards to passing data between view and vm Prism is fantastic, and passing back, maybe mvvm light wasn't the correct call, UI specific stuff can be abstracted away and injected via IoC, if it's a 4 page app that just does device specific work then I'd agree there may be no value.

    Having just finished delivering an app with 10 modules that delivers over 90 pages, I know that an MVVM framework is invaluable.

  • hutchinskihutchinski USMember ✭✭

    I will probably be shot down in flames here, but for a single developer project, where either azure web services or AWS are used for the back end and the app has only three pages, is MVVM, dependency injection and the complexity that comes with this, just a stumbling block for an awful lot of developers who might have embraced Xamarin? To me, the beauty of Xamarin lies in its simplicity (for cross platform apps). The code seems incredibly logical, clear and precise. The reasoning behind the separation of view from business logic is clear, however the way this is currently explained using MVVM and dependency injection concepts as abstractions may be putting off alot of new developers. Surely, after all this time, there must be simpler templates for basic single dev apps that Xamarin can promote, and teach in the Xamarin University course.

Sign In or Register to comment.