Last active
May 5, 2018 14:31
-
-
Save Macorreag/d912fa121610d48b12ae17c54166aa84 to your computer and use it in GitHub Desktop.
Pattern Decorator
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
package logica; | |
public class CalculoIntegral extends CursoRefuerzo { | |
private String actividades; | |
public CalculoIntegral() { | |
//Logica para acceder a los cursos | |
actividades = "Sumas de Riemann - Integrales indefinidas - Longitud de curvas - " | |
+ "Sólidos de revolución - Series - Radio de convergencia"; | |
} | |
@Override | |
public String getActividades() { | |
return actividades; | |
} | |
@Override | |
public void setActividades(String actividades) { | |
this.actividades = actividades; | |
} | |
} | |
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
package logica; | |
public abstract class CursoDecorator extends CursoRefuerzo{ | |
private CursoRefuerzo curso; | |
private String actividades; | |
public CursoDecorator(CursoRefuerzo curso) { | |
this.curso = curso; | |
} | |
public CursoRefuerzo getCurso() { | |
return curso; | |
} | |
/* | |
* El Decorador reescribe los metodos de la clase superior para tener una nueva | |
* funcionalidad pero que implementan la funcionalidad de la clase mas superior | |
* */ | |
@Override | |
public String getActividades() { | |
return actividades; | |
} | |
@Override | |
public void setActividades(String actividades) { | |
this.actividades = actividades; | |
} | |
} | |
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
package logica; | |
public abstract class CursoRefuerzo { | |
public abstract String getActividades(); | |
public abstract void setActividades(String actividades); | |
} | |
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
package logica; | |
public class CursoVacio extends CursoRefuerzo { | |
private String actividades; | |
public CursoVacio() { | |
//Logica para acceder a los cursos | |
actividades = ""; | |
} | |
@Override | |
public String getActividades() { | |
return actividades; | |
} | |
@Override | |
public void setActividades(String actividades) { | |
this.actividades = actividades; | |
} | |
} | |
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
package logica; | |
public class IntegralesIndefinidas extends CursoDecorator { | |
public IntegralesIndefinidas(CursoRefuerzo curso) { | |
super(curso); | |
} | |
@Override | |
public String getActividades() { | |
// Logica para agregar las actividades | |
String actividades = getCurso().getActividades() + " Integrales Indefinidas -"; | |
/* | |
* Se sobreescribiran las actividades en la primera ejecucion tendremos " "" + " Integrales Indefinidas -" " | |
* lo que modificara las actividades gracias al decorador que se implemento CursoDecorator | |
* */ | |
return actividades; | |
} | |
} | |
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
import presentacion.Modelo; | |
public class Launcher { | |
private Modelo aplicacion; | |
public Launcher() { | |
aplicacion = new Modelo(); | |
aplicacion.ejecutar(); | |
} | |
public static void main(String[] args) { | |
new Launcher(); | |
} | |
} |
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
package presentacion; | |
import logica.CalculoIntegral; | |
import logica.CursoRefuerzo; | |
import logica.CursoVacio; | |
import logica.IntegralesIndefinidas; | |
import logica.Salida; | |
import logica.SalidaConsola; | |
import logica.Series; | |
public class Modelo { | |
//Creacion curso completo | |
private CursoRefuerzo curso, curso1; | |
private Salida salida; | |
public void ejecutar() { | |
//Creacion curso completo | |
curso = new CalculoIntegral(); | |
//Se instancia una clase CursoRefuerzo con una clase que hereda de la misma | |
//Curso refuerzo pero tiene las actividades de calculo integral | |
//Curso con loss temas que el estudiante necesita | |
//Curso con los temas que el estudiante necesita | |
curso1 = new CursoVacio(); | |
//mismo anterior pero no tiene actividades | |
curso1 = new IntegralesIndefinidas(curso1); | |
curso1 = new Series(curso1); | |
salida = new SalidaConsola(); | |
salida.imprimir("Curso completo"); | |
salida.imprimir(curso.getActividades()); | |
salida.imprimir("Curso Temas Seleccionados"); | |
salida.imprimir(curso1.getActividades()); | |
} | |
} | |
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
package logica; | |
public abstract class Salida { | |
public abstract void imprimir(String a); | |
} |
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
package logica; | |
public class SalidaConsola extends Salida { | |
@Override | |
public void imprimir(String a) { | |
System.out.println(a); | |
} | |
} |
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
package logica; | |
public class Series extends CursoDecorator { | |
public Series(CursoRefuerzo curso) { | |
super(curso); | |
} | |
@Override | |
public String getActividades() { | |
// Logica para agregar las actividades | |
String actividades = getCurso().getActividades() + " Series -"; | |
return actividades; | |
} | |
} | |
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
package logica; | |
public class SumasdeRiemann extends CursoDecorator{ | |
public SumasdeRiemann(CursoDecorator curso) { | |
super(curso); | |
} | |
@Override | |
public String getActividades() { | |
// Logica para agregar las actividades | |
String actividades = getCurso().getActividades() + " Sumas de Riemann"; | |
return actividades; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment