Created
April 8, 2019 16:55
-
-
Save XixoWreden/416014f415285e01d2c1dc73374a8ea5 to your computer and use it in GitHub Desktop.
Implementación del Patron de Diseño Interfaz Fluida con ejemplo para observar lo facil de su uso.
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
/* | |
* CLASE MAIN PARA PROBAR EL Java Fluent Interface | |
* QUE NOS PERMITIRA TRABAJR UN POCO MAS FLUIDO CUANDO PROGRAMAMOS | |
*/ | |
public class TestPatterns { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
//LO BUENO DEL PATRON DE DISEÑO INTEFAZ FLUIDA ES CUANDO REQUIERES USAR | |
//SUS METODOS. | |
CorreoPropertie cpropertie = new CorreoPropertie(); | |
//*******En vez de realizar esto********* | |
/* | |
cpropertie.setCorreo("Un correo", "nuevo"); | |
cpropertie.setMensaje("Un Mensaje", "reusado"); | |
cpropertie.setTitulo("Un Titulo", "nuevo"); | |
*/ | |
//Se puede usar en una sola linea. | |
cpropertie.setCorreo("Un correo") | |
.setMensaje("Un Mensaje") | |
.setTitulo("Un Titulo"); | |
System.out.println("SE IMPRIME:"+cpropertie.getCorreo()); | |
System.out.println("SE IMPRIME:"+cpropertie.getMensaje()); | |
System.out.println("SE IMPRIME:"+cpropertie.getTitulo()); | |
} | |
} | |
/* | |
* CLASE QUE IMPLEMENTA LA INTERFAZ FLUIDA, DONDE LOS SETTERS QUE | |
* IMPLEMENTA EL PATRÓN RETORNAN EL MISMO OBJETO DE LA CLASE PADRE. | |
*/ | |
class CorreoPropertie { | |
private Properties propiedades = new Properties(); | |
public CorreoPropertie setCorreo(String valor) { | |
propiedades.setProperty("correo", valor); | |
return this; | |
} | |
public String getCorreo() { | |
return propiedades.getProperty("correo"); | |
} | |
public CorreoPropertie setTitulo(String valor) { | |
propiedades.setProperty("titulo", valor); | |
return this; | |
} | |
public String getTitulo() { | |
return propiedades.getProperty("titulo"); | |
} | |
public CorreoPropertie setMensaje(String valor) { | |
propiedades.setProperty("mensaje", valor); | |
return this; | |
} | |
public String getMensaje() { | |
return propiedades.getProperty("mensaje"); | |
} | |
} | |
/* | |
* CLASE DE APOYO PARA LA CLASE CORREOPROPERTIE | |
*/ | |
class Properties { | |
private String property; | |
private String valor; | |
public String getProperty(String titulo) { | |
return titulo+"["+valor+"]"+":["+property+"]"; | |
} | |
public void setProperty(String property, String valor) { | |
this.property = property; | |
this.valor = valor; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Se tomó el ejemplo del blog:
https://www.arquitecturajava.com/java-fluent-interface-y-properties/
También para tomaron estas páginas de referencia: