I started using OO a short time ago and in all projects that I see on the net, I see the following way of declaration.
public class Trabalhador
{
public int Id { get; set; }
public string Nome { get; set; }
public virtual ICollection Dependente { get; set; }
public virtual ICollection Dependente { get; set; }
public virtual ICollection LicencaMedica{ get; set; }
}
public class Dependente
{
public int ID { get; set; }
public string Nome { get; set; }
public virtual Trabalhador Trabalhador { get; set; }
}
public class Ferias
{
public int ID { get; set; }
public string Nome { get; set; }
public virtual Trabalhador Trabalhador { get; set; }
}
public class LicencaMedica
{
public int ID { get; set; }
public string Nome { get; set; }
public virtual Trabalhador Trabalhador { get; set; }
}
In the meantime I am working on a project together with other developers, and one of them rightly argues that my classes should not have the "virtual" as navigation attribute, he argues that the classes Dependent, Fairs and License by Since they already have an ICollection in Worker, they should not have any keys, because they will all be accessible from the working class, is this correct from the point of view of OO? I explained my opinion and said that this was wrong, because it would be kind of creating a Root class and everything would pass through it without need, rather than overloading a class with a lot of responsibility, his approach would be as follows:
public class Trabalhador
{
public int Id { get; set; }
public string Nome { get; set; }
public virtual ICollection Dependente { get; set; }
public virtual ICollection Dependente { get; set; }
public virtual ICollection LicencaMedica{ get; set; }
}
public class Dependente
{
public int? ID { get; set; }
public string Nome { get; set; }
}
public class Ferias
{
public int? ID { get; set; }
public string Nome { get; set; }
}
public class LicencaMedica
{
public int? ID { get; set; }
public string Nome { get; set; }
}
Is this correct from the point of view of OO? For me to have access to a child class object should I necessarily pass through the parent class? According to him the Ninject which accuses error in the system, because the fact of instantiating the parent class and then instantiating the daughter class according to it would loop in the system, so it starts all the navigation properties of the child classes.
(We are not using Entity, we are using ADO with SP in the Bank). I tried to be as specific as possible, what is the problem with each approach?