Change of object in inheritance

4

I have the following classes:

class Funcionario {
}

class Coordenador : Funcionario {
}

class Gerente : Funcionario {
}

At that point a Coordinator can become a Manager.

How to solve this?

    
asked by anonymous 22.03.2017 / 15:42

2 answers

8

Depends heavily on requirements. I would not do it with inheritance. It seems to me that the role (role) of the person is a transient situation , so I would make a composition.

When you completely change the object in the background it is another person, even if you keep the data almost the same, it would be a new identity, this is conceptually wrong. It does not make sense and would complicate the persistence in ways you can not even imagine.

Inheritance is one of the most abused programming features nowadays. It should only be used when it actually brings some advantage over the disadvantages. Was this analysis done? Can you 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 {
    ...
}

See:

If I had a better understanding of every situation, I might have given a different solution.

    
22.03.2017 / 16:07
0

You look polymorphic. Although they both inherit Employee , the Coordinator class should not have the same Coordinator-specific assignments, and vice versa, except for those properties that share Employee. For example, Coordinator and Manager can use the Name, Age, and Employer Address property but an overload of the Daily Activities method, for example, not. So, in the case of a promotion, the coordinator John would stop using the Coordinator and rather the Manager (But both remain Officer). See this link, a theoretical idea about polymorphism.

When and why should we use polymorphism?

    
22.03.2017 / 21:42