I've read a lot of content on this topic until I get to this example:
public interface Funcionario{
public void trabalha();
public void recebe(double salario);
}
public abstract class Geek implements Funcionario{
public abstract void trabalha();
public abstract void recebe(double salario);
public void programa(){
System.out.println("import java.io.*; :) ");
}
}
public abstract class BusinessMan implements Funcionario{
public void trabalha(){
System.out.println("$$$");
}
public abstract void recebe(double salario);
}
// programador é um geek e também um funcionário...
public class Programador extends Geek{
private double salario;
public void trabalha(){
super.programa();
}
public void recebe(double salario){
this.salario = salario;
}
}
/* analista também é um geek e um funcionário, mas que trabalha de maneira diferente ao programador*/
public class Analista extends Geek{
private double salario;
public void trabalha(){
super.programa();
supervisionaProjeto();
}
public void recebe(double salario){
this.salario = salario;
}
private void supervisionaProjeto(){
System.out.println("Supervisiona");
}
}
public class Gerente extends BusinessMan{
private double salario;
private final double BONUS = 1000.0d;
public void recebe(double salario){
this.salario = salario + this.BONUS;
}
}
public class Empresa{
public static void main(String[] args){
private Funcionario[] funcionario = new Funcionario[5];
funcionario[0] = new Programador();
funcionario[1] = new Programador();
funcionario[2] = new Analista();
funcionario[3] = new Programador();
funcionario[4] = new Gerente();
// faz alguma coisa...
}
}
Source: link
I changed the interface Funcionario
by a class library, and made the other classes, which before implemented, now extend it. So:
public abstract class Funcionario {
public abstract void trabalha();
public abstract void recebe(double salario);
}
public abstract class Geek extends Funcionario{
@Override
public abstract void trabalha();
@Override
public abstract void recebe(double salario);
public void programa() {
System.out.println("import java.io.*; :) ");
}
}
public abstract class BusinesMan extends Funcionario {
@Override
public void trabalha() {
System.out.println("$$$");
}
@Override
public abstract void recebe(double salario);
}
There was no change at all when compiling and rolling.
My question is: Does this specific case change anything with these changes? Do you have any functionality that I will lose or win?
Note: I'm not referring to performance. I'm referring to the issue of maintenance or complexity, for example, if I later need to add any more type of employee, is there going to be a difference in both cases?