4
I have the following classes:
class Funcionario {
}
class Coordenador : Funcionario {
}
class Gerente : Funcionario {
}
There a certain moment a Coordinator can become a Manager.
How to solve this?
4
I have the following classes:
class Funcionario {
}
class Coordenador : Funcionario {
}
class Gerente : Funcionario {
}
There a certain moment a Coordinator can become a Manager.
How to solve this?
8
It depends a lot on the requirements. I wouldn’t do that with inheritance. It seems to me that the function (role) of the person is a transitional situation, then I would make a composition.
When you change the object completely in the background is another person, even if you keep the data practically equal, it would be a new identity, this is conceptually wrong. It makes no sense and would complicate persistence in ways you can’t imagine.
Inheritance is one of the most abused features of programming today. It should only be used when it really brings some advantage greater than the disadvantages. Has this analysis been made? You can confirm that it is the best solution and the composition is not so good?
class Funcionario {
public string Nome { get; set; }
public int Idade { get; set; }
public Funcao { get; set; } //aqui coloca a função do momento
}
class Funcao {
...
}
I put in the Github for future reference.
Behold:
If I knew better the whole situation maybe I would give a different solution.
0
You look like a polymorphist. Although they both inherit Functionary, the class Coordinator, shall not have the same specific Coordinator roles and vice versa, except the Employee-sharing properties. For example, Coordinator and Manager may use the Name, Age and Employee Address property but a virtual method overload Activities for example no. Thus, in the case of a promotion, the coordinator John would no longer use the Class Coordinator rather that of Manager (But both remain Functionary). See this link, a theoretical idea about polymorphism.
Browser other questions tagged c# oop inheritance
You are not signed in. Login or sign up in order to post.