Last active
November 27, 2023 17:34
-
-
Save miguelsmuller/4e09d3aa69bbe44bfa0eed4902b9841f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Pessoa { | |
private Departamento departamento; | |
public Pessoa(Departamento departamento) { | |
this.departamento = departamento; | |
} | |
// RESPEITA a Lei de Demeter | |
public String obterNomeChefeDaEquipe() { | |
return departamento.obterNomeDoGerente(); | |
} | |
} | |
public class Departamento { | |
private Pessoa gerente; | |
public Departamento(Pessoa gerente) { | |
this.gerente = gerente; | |
} | |
public Pessoa getGerente() { | |
return gerente; | |
} | |
// Método de nível mais alto para | |
// obter o nome do gerente | |
public String obterNomeDoGerente() { | |
return gerente.getNome(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Pessoa { | |
private Departamento departamento; | |
public Pessoa(Departamento departamento) { | |
this.departamento = departamento; | |
} | |
// A VIOLAÇÃO ocorre ao acessar diretamente o nome | |
// do gerente do departamento, envolvendo múltiplos | |
// níveis de acesso e conhecimento interno da | |
// estrutura dos objetos. | |
public String obterNomeChefeDaEquipe() { | |
return departamento.getGerente().getNome(); | |
} | |
} | |
public class Departamento { | |
private Pessoa gerente; | |
public Departamento(Pessoa gerente) { | |
this.gerente = gerente; | |
} | |
public Pessoa getGerente() { | |
return gerente; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment