@Ana, in addition to using the constructor, also validate the methods, so you create invariants for your class and impose rules for the states that your class can be. In other words, do not just create a manager with a number of Employees quantity
It is important to ensure that this quantidaed is >= 0
(greater than or equal to zero) or even greater than zero.
Another important validation at the time of creation is making sure that the users in your class will not define a name nulo
or empty ""
public Gerente(String nome, int quantidadeFuncionarios) {
if(nome == null || nome.isEmpty()){
throw new IllegaArgumentException("Nome não pode ser vazio");
}
if(quantidadeFuncionarios < 0){
throw new IllegalArgumentException("Quantidade funcionarios não opde ser inferior a zero");
}
this.setNome(nome); // herdando do funcionário
this.quantidadeFuncionarios = quantidadeFuncionarios;
}
The best way to actually force your objects to be in a valid state is this.
Please call this exception: link
Consider making your objects immutable.
Another way to secure the invariants of your class is to redraw it to be immutable.
There are some trade offs to consider, check out this tutorial:
link