vendredi 30 octobre 2020

What is difference between model class and data class?

I'm new to web development and I'm struggling to differentiate between a model class and a data class, specially when implementing them.

I found this question and I kind of understood the theory about it: the data class contains all the core information about an object and a model class only contains the information that needs to be exposed. So I can have a user data class like this:

public class User {
    public long Id { get; set; }

    public string Name { get; set; }

    public string Password { get; set; }

    public string Email { get; set; }

    public int Score { get; set; }
}

And a model class for the login page like this:

public class UserModel {
    [Required]
    public string Password { get; set; }

    [Required]
    [EmailAdress]
    public string Email { get; set; }
}

And I would have to create another model class for sign up, for example, adding the Name and Password properties. But do I need to be repeating the same properties for each new model? Do the models need to inherit from User data class? Is all of this specific to MVC pattern? How do the model data classes relate to each other?

I'm using Blazor WebAssembly if that helps.




Aucun commentaire:

Enregistrer un commentaire