Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# WPF MVVM can I do this without making the view model variables mutable?

Tags:

mvvm

wpf

f#

I'm learning F#, I want to build the next module of my home project. So far most of my F# code has been test code written with the command line. I also did some custom drawing to a Winforms Panel. So far, I haven't had to use one mutable variable. but now I'm trying to write some actual code and as soon as I got to the ViewModel part it seemed that I had no choice but to make the variables that will interact with the UI mutable. Is this true, or is there something I'm missing?

like image 590
Jesse Avatar asked Feb 06 '17 04:02

Jesse


1 Answers

For MVVM, F# carries one very significant advantage: it does not allow circular dependencies. This makes it very difficult to break the pattern: i.e. to allow the model to directly affect the viewmodel, or the viewmodel to access the view. As Bent says, F# is multi-paradigm: it supports properties with getters and setters, and these are not things to be eschewed in the language.

It's interesting that I'm citing a lack of capability as one of the advantages of F#, but I feel it is precisely this preclusion of circular dependencies that makes the language a good choice for an enterprise architecture.

I have a toy project at https://github.com/SpiegelSoft/Astrid. You can look through that to see how I've implemented MVVM using ReactiveUI.

like image 117
Rob Lyndon Avatar answered Oct 20 '22 09:10

Rob Lyndon