The scenario:
I have a GUI with textfields and radio buttons where the user insert information for a 'Person'
Here are the classes of the model and of the view-model:
enum Gender
{
case Male, Female
}
class Person
{
var name: String = ""
var surname: String = ""
var id: String = ""
var gender: Gender?
setDataFromViewModel(model: PersonViewModel)
{
// doing stuff
}
}
class PersonViewModel
{
var name: String = ""
var surname: String = ""
var id: String = ""
var gender: Gender?
init(person: Person)
{
// doing stuff with the strings to make them nice
}
}
If I already have the data the PersonViewModel will get it from the Person and give it to the view.
If the user in writing the data the PersonViewModel will get it first, and pass it to the Person model.
Questions: If I have to check integrity of the strings coming from the View, where should I do it? (checking that the string is not empty, that the ID match a certain regex, etc).
Is this an optimal implementation of the pattern ora am I missing something?
PersonViewModel
, assuming that's the data that will be passed to the server when the "save button" is pressed.