-
-
Save pablovillacanas/e6a2f50f30c4a1ce768b7ff06486b194 to your computer and use it in GitHub Desktop.
Example for strategy pattern
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 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