Tworzę sobie model użytkownika i mam pytanie.
- Proszę o ocenę poniższego fragmencika kodu, czy tak to powinno wyglądać.
- Jak w klasie potomnej zainicjować pole z klasy z której dziedziczę? Czym będą się różniły te sposoby przy których są komentarze?
Mam taki kod:
Klasa bazowa:
public abstract class BaseEntity
{
public Guid Id { get; set; }
}
i klasa dziedzicząca
public class User : BaseEntity
{
public string Name { get; protected set; }
public string Lastname { get; protected set; }
public string Login { get; protected set; }
public string Email { get; protected set; }
public string Password { get; protected set; }
public string Salt { get; protected set; }
public string Role { get; protected set; }
public DateTime CreatedUtc { get; protected set; }
public User(string login, string email, string password, string salt )
{
base.Id = new Guid(); // czy tak się powinno robić?
Id = new Guid(); // czy tak?
Login = login;
Email = email.ToLowerInvariant();
Password = password;
Salt = salt;
CreatedUtc = DateTime.UtcNow;
}
}