Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • So basically you are saying that it's OK for a ProductViewModel item to know that it is a part of a collection. I am on the fence about that but tend to think that the collection level validation should be injected in somehow. BTW this is sort of related but having a strongly typed backing variable splits the data validation between the View and the ViewModel. EG if you type a non-numeric char into the Id edit cell, then the View will intercept that and supply its own error message. The only way around that is to change the backing variables to be strings. Which I loathe. Commented Nov 29, 2017 at 18:17
  • Actually I am now wondering if all validation shouldn't be injected into the ProductViewModel Commented Nov 29, 2017 at 18:20
  • In general, I think injecting the validator is a good thing. The validator could have a reference to the product Collection and then be able to perform the collection level validation. About the strongly typed backing variable, I see no problem in having only string properties in your VM, if your GUI enables the user to type text chars. By doing so, you would be able to implement everything in the ViewModel and also test stuff. I don't see this as a problem. You could have string properties, and in the end a method that generate the Product object (with correct types). Commented Nov 29, 2017 at 18:37
  • I have been trying to avoid string backing variables in order to keep as close as possible to the data model. But it is looking more and more like I can't avoid them. Commented Nov 29, 2017 at 18:44
  • 1
    I took your code and ran with it adding my own spin Commented Nov 30, 2017 at 14:23