Skip to content

Instantly share code, notes, and snippets.

@pablovillacanas
Last active June 14, 2018 10:59
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 pablovillacanas/e6a2f50f30c4a1ce768b7ff06486b194 to your computer and use it in GitHub Desktop.
Save pablovillacanas/e6a2f50f30c4a1ce768b7ff06486b194 to your computer and use it in GitHub Desktop.
Example for strategy pattern
public static void main (String[] args){
Perro perro = new Perro();
Ladrido ladrido = new Ladrido("Guau"); //Ladrido extiende de Sonido
Lamento lamento = new Lamento("Mphii"); //Lamento extiende sonido tambien
perro.setSonido(ladrido);
System.out.println(perro.getSonido().emitirSonido()); //Guau!
perro.setSonido(lamento);
System.out.println(perro.getSonido().emitirSonido()); //Mphii
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment