Skip to content

Commit

Permalink
memoizacao com lazy instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
vigusmao committed Apr 14, 2021
1 parent 53e30fd commit 63a678d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Fracao/src/Fracao.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public Fracao(int numerador, int denominador) {

this.sinal = Math.signum(numerador) == Math.signum(denominador) ||
numerador == 0;

obterFracaoGeratriz();
}

/**
Expand Down Expand Up @@ -84,6 +82,10 @@ public float getValorNumerico() {
* esta própria fração (this), se ela já for irredutível
*/
public Fracao getFracaoGeratriz() {
if (fracaoGeratriz == null) {
obterFracaoGeratriz(); // lazy instantiation
}

return fracaoGeratriz;
}

Expand Down

0 comments on commit 63a678d

Please sign in to comment.