Skip to content

Instantly share code, notes, and snippets.

@tiagox
Created May 23, 2018
Embed
What would you like to do?

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