-
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(prototype): Se agrega patron creacional de objetos
- Loading branch information
Stephano Apiolaza
committed
Jan 28, 2018
1 parent
ab61fad
commit ae302a5
Showing
15 changed files
with
501 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
description = 'The Prototype patron creacional de objetos' | ||
|
||
dependencies { | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/Figura.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.prototype; | ||
|
||
/** | ||
* Clase que representa el patron de disenno prototype | ||
* Interfaz de comunicacion con Cloneable, | ||
* este se utiliza para indicar que la clase puede ser clonada, | ||
* retornando un objeto inmutable | ||
* | ||
* @see {@link https://www.tutorialspoint.com/design_pattern/prototype_pattern.htm} | ||
* @category Patrones Creacionales - Objeto | ||
* @version 1.0 - 27-01-18 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
public abstract class Figura implements Cloneable{ | ||
|
||
private String id; | ||
|
||
/** | ||
* Metodo heredado que permite obtener un texto de la figura geometrica a que pertenece | ||
*/ | ||
public abstract String getDibujo(); | ||
|
||
/** | ||
* Permite clonar un objeto para aplicar patron prototype | ||
* @return objeto inmutable | ||
*/ | ||
public Object clone() { | ||
Object clone = null; | ||
try { | ||
clone = super.clone(); | ||
}catch(CloneNotSupportedException e) { | ||
e.printStackTrace(); | ||
} | ||
return clone; | ||
} | ||
|
||
/** | ||
* Get id element | ||
* @return id | ||
*/ | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* Set id element | ||
* @param id element | ||
*/ | ||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
|
||
|
||
} |
117 changes: 117 additions & 0 deletions
117
prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/FiguraCache.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,117 @@ | ||
/* | ||
* 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.prototype; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.stephanoapiolaza.dessignpattern.prototype.constants.ConstantsPrototype; | ||
import com.stephanoapiolaza.dessingpattern.prototype.impl.Circulo; | ||
import com.stephanoapiolaza.dessingpattern.prototype.impl.Cuadrado; | ||
import com.stephanoapiolaza.dessingpattern.prototype.impl.Triangulo; | ||
|
||
/** | ||
* Clase que representa el patron de disenno prototype | ||
* director para manipulacion de cache, retornando objetos inmutables | ||
* | ||
* @see {@link https://www.tutorialspoint.com/design_pattern/prototype_pattern.htm} | ||
* @category Patrones Creacionales - Objeto | ||
* @version 1.0 - 27-01-18 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
public class FiguraCache { | ||
|
||
private static Map<String, Figura> figuraMap = new HashMap<>(); | ||
/** | ||
* Constructor Privado | ||
*/ | ||
private FiguraCache() { | ||
|
||
} | ||
|
||
/** | ||
* Retorna una figura de acuerdo al identificador solicitado | ||
* @param key identificador | ||
* @return figura solicitada | ||
*/ | ||
public static Figura getFigura(String key) { | ||
Figura figura = figuraMap.get(key); | ||
return (Figura) figura.clone(); | ||
} | ||
|
||
/** | ||
* Metodo que simula llamadas a la base de datos para llenado | ||
*/ | ||
public static void loadCache() { | ||
doCircle(); | ||
doSquare(); | ||
doTriangle(); | ||
} | ||
|
||
/** | ||
* Permite insertar un elemento en el mapa sincronizado | ||
* @param id key | ||
* @param obj value | ||
*/ | ||
private static void insertElement(String id, Figura obj) { | ||
figuraMap.put(id, obj); | ||
} | ||
|
||
/** | ||
* Inserta un elemento de tipo figura | ||
* @param obj de tipo figura | ||
*/ | ||
private static void insertFigura(Figura obj) { | ||
insertElement(obj.getId(), obj); | ||
} | ||
|
||
/** | ||
* Permite insertar un circulo | ||
*/ | ||
private static void doCircle() { | ||
Figura figura = new Circulo(); | ||
figura.setId(ConstantsPrototype.ID_CIRCLE); | ||
insertFigura(figura); | ||
} | ||
|
||
/** | ||
* Permite insertar un cuadrado | ||
*/ | ||
private static void doSquare() { | ||
Figura figura = new Cuadrado(); | ||
figura.setId(ConstantsPrototype.ID_SQUARE); | ||
insertElement(figura.getId(), figura); | ||
} | ||
|
||
/** | ||
* Permite insertar un triangulo | ||
*/ | ||
private static void doTriangle() { | ||
Figura figura = new Triangulo(); | ||
figura.setId(ConstantsPrototype.ID_TRIANGLE); | ||
insertElement(figura.getId(), figura); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...main/java/com/stephanoapiolaza/dessignpattern/prototype/constants/ConstantsPrototype.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,50 @@ | ||
/* | ||
* 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.prototype.constants; | ||
|
||
/** | ||
* Clase con constantes para las salidas del dibujo | ||
* | ||
* @see {@link https://www.tutorialspoint.com/design_pattern/factory_pattern.htm} | ||
* @category Patrones Creacionales - Clase | ||
* @version 1.0 - 21-01-18 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
public class ConstantsPrototype { | ||
|
||
public static final String ID_CIRCLE = "1"; | ||
public static final String ID_SQUARE = "2"; | ||
public static final String ID_TRIANGLE = "3"; | ||
|
||
public static final String OUTPUT_CIRCLE = "Yo soy un circulo"; | ||
public static final String OUTPUT_SQUARE = "Yo soy un cuadrado"; | ||
public static final String OUTPUT_TRIANGLE = "Yo soy un triangulo"; | ||
|
||
/** | ||
* Constructor oculto | ||
*/ | ||
private ConstantsPrototype() {} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...e/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/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.prototype.constants; |
8 changes: 8 additions & 0 deletions
8
prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/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 representacion del patron de disenno factory | ||
* | ||
* @version 1.0 - 21-01-2018 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
package com.stephanoapiolaza.dessignpattern.prototype; |
49 changes: 49 additions & 0 deletions
49
prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Circulo.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,49 @@ | ||
/* | ||
* 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.dessingpattern.prototype.impl; | ||
|
||
import com.stephanoapiolaza.dessignpattern.prototype.Figura; | ||
import com.stephanoapiolaza.dessignpattern.prototype.constants.ConstantsPrototype; | ||
|
||
/** | ||
* Clase que representa el patron de disenno prototype | ||
* Modelo con comunicacion con la interfaz | ||
* | ||
* @see {@link https://www.tutorialspoint.com/design_pattern/prototype_pattern.htm} | ||
* @category Patrones Creacionales - Objeto | ||
* @version 1.0 - 21-01-18 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
public class Circulo extends Figura{ | ||
|
||
/** | ||
* Metodo que retorna el tipo de dibujo a que pertenece | ||
*/ | ||
@Override | ||
public String getDibujo() { | ||
return ConstantsPrototype.OUTPUT_CIRCLE; | ||
} | ||
|
||
} |
Oops, something went wrong.