-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DP01 - feat(creational.pattern): Se agrega singleton, builder y facto…
…ry patterns
- Loading branch information
Stephano Apiolaza
committed
Jan 21, 2018
1 parent
7c97c35
commit ab61fad
Showing
35 changed files
with
1,068 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
description = 'The Builder patron creacional de objetos' | ||
|
||
dependencies { | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/IngenieroSoftware.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) [2018] [Stephano Apiolaza] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package com.stephanoapiolaza.dessignpattern.builder; | ||
|
||
import com.stephanoapiolaza.dessignpattern.builder.model.Producto; | ||
import com.stephanoapiolaza.dessignpattern.builder.model.Software; | ||
|
||
/** | ||
* Clase que representa el patron de disenno builder, | ||
* esto se utiliza para crear objetos complejos, | ||
* permitiendo cambiar la representacion o los datos | ||
* de cada objeto de manera sencilla | ||
* | ||
* Este ejemplo se basara en la construccion de sistemas informaticos | ||
* | ||
* @see {@link https://www.tutorialspoint.com/design_pattern/builder_pattern.htm} | ||
* @category Patrones Creacionales - Objetos | ||
* @version 1.0 - 21-01-18 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
public class IngenieroSoftware { | ||
|
||
private Producto productoSoftware; | ||
|
||
/** | ||
* Permite asignar una instancia de producto a crear | ||
* @param producto a crear | ||
*/ | ||
public void setProducto(Producto producto) { | ||
this.productoSoftware = producto; | ||
} | ||
|
||
/** | ||
* Retorna el producto de software | ||
* @return instancia de producto de software con su representacion (datos) | ||
*/ | ||
public Software getProducto() { | ||
return productoSoftware.getSoftware(); | ||
} | ||
|
||
/** | ||
* Crea un flujo de creacion de productos | ||
*/ | ||
public void crearProducto() { | ||
this.productoSoftware.newInstance(); | ||
this.productoSoftware.setLenguaje(); | ||
this.productoSoftware.setCantidadUsuarios(); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...src/main/java/com/stephanoapiolaza/dessignpattern/builder/constants/ConstantsBuilder.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) [2018] [Stephano Apiolaza] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package com.stephanoapiolaza.dessignpattern.builder.constants; | ||
|
||
/** | ||
* Clase con constantes para representacion o datos del patron builder | ||
* | ||
* @see {@link https://www.tutorialspoint.com/design_pattern/builder_pattern.htm} | ||
* @category Patrones Creacionales - Objetos | ||
* @version 1.0 - 21-01-18 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
public class ConstantsBuilder { | ||
|
||
public static final String LENGUAJE_NETFLIX = "NodeJS"; | ||
public static final String LENGUAJE_SPOTIFY = "C++"; | ||
public static final int CANT_USER_NETFLIX = 300_000_000; | ||
public static final int CANT_USER_SPOTIFY = 100_000_000; | ||
|
||
/** | ||
* Constructor oculto | ||
*/ | ||
private ConstantsBuilder() {} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...der/src/main/java/com/stephanoapiolaza/dessignpattern/builder/constants/package-info.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Paquete de constantes para su reutilizacion | ||
* | ||
* @version 1.0 - 21-01-2018 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
package com.stephanoapiolaza.dessignpattern.builder.constants; |
51 changes: 51 additions & 0 deletions
51
builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Netflix.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) [2018] [Stephano Apiolaza] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package com.stephanoapiolaza.dessignpattern.builder.model; | ||
|
||
import com.stephanoapiolaza.dessignpattern.builder.constants.ConstantsBuilder; | ||
|
||
/** | ||
* Clase que representa el patron de disenno builder, | ||
* Modelo que define la representacion o datos del | ||
* producto de software musical llamado Netflix | ||
* | ||
* @see {@link https://www.tutorialspoint.com/design_pattern/builder_pattern.htm} | ||
* @category Patrones Creacionales - Objetos | ||
* @version 1.0 - 21-01-18 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
public class Netflix extends Producto{ | ||
|
||
@Override | ||
public void setLenguaje() { | ||
super.software.lenguaje(ConstantsBuilder.LENGUAJE_NETFLIX); | ||
} | ||
|
||
@Override | ||
public void setCantidadUsuarios() { | ||
super.software.cantidadUsuarios(ConstantsBuilder.CANT_USER_NETFLIX); | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Producto.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) [2018] [Stephano Apiolaza] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package com.stephanoapiolaza.dessignpattern.builder.model; | ||
|
||
/** | ||
* Clase que representa el patron de disenno builder, | ||
* Abstracta para la representacion de productos de software, | ||
* es decir, que se venden bajo licenciamiento | ||
* | ||
* @see {@link https://www.tutorialspoint.com/design_pattern/builder_pattern.htm} | ||
* @category Patrones Creacionales - Objetos | ||
* @version 1.0 - 21-01-18 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
public abstract class Producto { | ||
|
||
protected Software software; | ||
|
||
/** | ||
* Retorna la instancia de software | ||
* @return instancia de software | ||
*/ | ||
public Software getSoftware() { | ||
return software; | ||
} | ||
|
||
/** | ||
* Crea una instancia manual de software | ||
*/ | ||
public void newInstance() { | ||
this.software = new Software(); | ||
} | ||
|
||
/** | ||
* Define un lenguaje de programacion del software | ||
*/ | ||
public abstract void setLenguaje(); | ||
|
||
/** | ||
* Define la cantidad de usuarios que soporta el software | ||
*/ | ||
public abstract void setCantidadUsuarios(); | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Software.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) [2018] [Stephano Apiolaza] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package com.stephanoapiolaza.dessignpattern.builder.model; | ||
|
||
/** | ||
* Clase que representa el patron de disenno builder, | ||
* Modelo POJO con el modelo a realizar, con metodos | ||
* con los nombres de los atributos para una facil creacion, evitando | ||
* constructores con multiples parametros | ||
* | ||
* @see {@link https://www.tutorialspoint.com/design_pattern/builder_pattern.htm} | ||
* @category Patrones Creacionales - Objetos | ||
* @version 1.0 - 21-01-18 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
public class Software { | ||
|
||
private String lenguaje; | ||
private int cantidadUsuarios; | ||
|
||
/** | ||
* Permite cambiar el atributo lenguaje | ||
* @param lenguaje a modificar | ||
* @return Instancia de la clase | ||
*/ | ||
public Software lenguaje(String lenguaje) { | ||
this.lenguaje = lenguaje; | ||
return this; | ||
} | ||
|
||
/** | ||
* Permite cambiar el atributo cantidadUsuarios | ||
* @param cantidadUsuarios a modificar | ||
* @return Instancia de la clase | ||
*/ | ||
public Software cantidadUsuarios(int cantidadUsuarios) { | ||
this.cantidadUsuarios = cantidadUsuarios; | ||
return this; | ||
} | ||
|
||
/** | ||
* Getter | ||
* @return lenguaje | ||
*/ | ||
public String getLenguaje() { | ||
return lenguaje; | ||
} | ||
|
||
/** | ||
* Getter | ||
* @return cantidad usuarios | ||
*/ | ||
public int getCantidadUsuarios() { | ||
return cantidadUsuarios; | ||
} | ||
|
||
} |
Oops, something went wrong.