Skip to content

Instantly share code, notes, and snippets.

@tiagox
Created May 23, 2018 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagox/21a90b57dbdfee658e52b8ab2b477e51 to your computer and use it in GitHub Desktop.
Save tiagox/21a90b57dbdfee658e52b8ab2b477e51 to your computer and use it in GitHub Desktop.

Patrón Adapter

import java.util.List;
public class AdaptadorDeSuma implements Sumable {
private Sumador sumador;
public AdaptadorDeSuma(Sumador sumador) {
this.sumador = sumador;
}
@Override
public int sumatoria(List<Integer> lista) {
int resultado = 0;
for (Integer valor : lista) {
resultado = sumador.sumar(resultado, valor);
}
return resultado;
}
}
import java.util.List;
public interface Sumable {
int sumatoria(List<Integer> lista);
}
public class Sumador {
public int sumar(int a, int b) {
return a + b;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment