Skip to content

Commit

Permalink
DP01 - feat(prototype): Se agrega patron creacional de objetos
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephano Apiolaza committed Jan 28, 2018
1 parent ab61fad commit ae302a5
Show file tree
Hide file tree
Showing 15 changed files with 501 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.3.0(27-01-2018)

### Features

* **prototype**: Se agrega patron creacional de objeto.

# 0.2.0(21-01-2018)

### Features
Expand Down
5 changes: 2 additions & 3 deletions build-config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
Included from: "${rootProject.projectDir}/build.gradle"
============================================================================
*/

// No se modifica versionn del proyecto, hasta externalizar en nexus o artifactory
version = "0.2.0"

version = "0.3.0"

subprojects {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
import com.stephanoapiolaza.dessingpattern.factory.impl.Triangulo;

/**
* Clase que representa el patron de disenno singleton
* Clase que representa el patron de disenno factory
* para crear instancias unicas por objeto, ayudando a su
* reutilizacion y optimizacion, ideal para realizar tareas
* de cache
*
* @see {@link https://www.tutorialspoint.com/design_pattern/singleton_pattern.htm}
* @category Patrones Creacionales
* @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
*
Expand Down
5 changes: 5 additions & 0 deletions prototype/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description = 'The Prototype patron creacional de objetos'

dependencies {

}
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;
}



}
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);
}

}
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() {}

}
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;
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;
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;
}

}
Loading

0 comments on commit ae302a5

Please sign in to comment.