6
I started using OO a short time and in all projects I see on the net, I see the following way of statement.
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; }
}
However I am working on a project together with other developers, and one of them argues tooth and nail that my classes should not have "virtual" as a navigation attribute, he argues that the Dependent classes, Holidays and License because they already have an Icollection in Worker, they should not have any key, as they will all be accessible from the working class, is that correct from the point of view of OO? I expressed my opinion and said that this was wrong, because I would be kind of creating a Root class and everything would go through it without need, kind of overloading a class with a lot of responsibility, his approach would be the following:
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 an object of the daughter class I must necessarily pass by the parent class? According to him the Ninject who accuses error in the system, because the fact of instantiating the parent class and then instantiating the daughter class according to him would give a loop in the system, so he rips off all navigation property of the daughter 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 of each of the approaches?
That’s why Jon Skeet thinks classes should be
sealed
for default. http://stackoverflow.com/a/6389669/221800. inheritance should be used as a last resort, when you actually have a relationship is-one, when this brings benefits. Thereforevirtual
doesn’t make sense if you don’t need polymorphism. Get used to creating your classes withselead
and only withdraw it if you find a good reason for this.– Maniero