Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exemplo de Henranca indevida #70

Merged
merged 1 commit into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Veja mais informações das lições aprendidas na [Wiki](https://github.com/jal

>### Boas práticas de código

* [Padrão Tell, don't ask e Fail Fast](https://github.com/jalussa-santos/formacao-arquitetura-design-projetos-java/issues/1)
* [Padrão Tell, don't ask](https://github.com/jalussa-santos/formacao-arquitetura-design-projetos-java/issues/1)
* [Padrão Fail Fast](https://github.com/jalussa-santos/formacao-arquitetura-design-projetos-java/issues/55)
* [Coesão](https://github.com/jalussa-santos/formacao-arquitetura-design-projetos-java/issues/2)
* [Encapsulamento](https://github.com/jalussa-santos/formacao-arquitetura-design-projetos-java/issues/58)
Expand Down
30 changes: 26 additions & 4 deletions solid-projeto-inicial/src/br/com/alura/rh/model/Cargo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,31 @@

public enum Cargo {

ASSISTENTE,
ANALISTA,
ESPECIALISTA,
GERENTE;
ASSISTENTE {
@Override
public Cargo getProximoCargo() {
return ANALISTA;
}
},
ANALISTA {
@Override
public Cargo getProximoCargo() {
return ESPECIALISTA;
}
},
ESPECIALISTA {
@Override
public Cargo getProximoCargo() {
return GERENTE;
}
},
GERENTE {
@Override
public Cargo getProximoCargo() {
return GERENTE;
}
};

public abstract Cargo getProximoCargo();

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ public void setDataUltimoReajuste(LocalDate dataUltimoReajuste) {
this.dataUltimoReajuste = dataUltimoReajuste;
}

public void promover(Cargo novoCargo) {
this.cargo = novoCargo;
}

}
20 changes: 20 additions & 0 deletions solid-projeto-inicial/src/br/com/alura/rh/model/Terceirizado.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package br.com.alura.rh.model;

import java.math.BigDecimal;

public class Terceirizado extends Funcionario {

private String empresa;

public Terceirizado(String nome, String cpf, Cargo cargo, BigDecimal salario) {
super(nome, cpf, cargo, salario);
}

public String getEmpresa() {
return empresa;
}

public void setEmpresa(String empresa) {
this.empresa = empresa;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package br.com.alura.rh.service.promocao;

import br.com.alura.rh.ValidacaoException;
import br.com.alura.rh.model.Cargo;
import br.com.alura.rh.model.Funcionario;

public class PromocaoService {

public void promover(Funcionario funcionario, boolean metaBatida) {
Cargo cargoAtual = funcionario.getCargo();
if (Cargo.GERENTE == cargoAtual) {
throw new ValidacaoException("Gerentes nao podem ser promovidos!");
}

if (!metaBatida) {
throw new ValidacaoException("Funcionario nao bateu a meta!");
}
Cargo novoCargo = cargoAtual.getProximoCargo();
funcionario.promover(novoCargo);
}

}