From ab61fad6923a7f2b6abb0619619b647bf39ecd59 Mon Sep 17 00:00:00 2001 From: Stephano Apiolaza Date: Sun, 21 Jan 2018 20:02:40 -0300 Subject: [PATCH 1/4] DP01 - feat(creational.pattern): Se agrega singleton, builder y factory patterns --- CHANGELOG.md | 8 ++ abstract-factory/build.gradle | 2 +- build-config.gradle | 9 ++- build-java.gradle | 3 +- libraries.gradle => build-libraries.gradle | 0 build.gradle | 2 +- builder/build.gradle | 5 ++ .../builder/IngenieroSoftware.java | 72 +++++++++++++++++ .../builder/constants/ConstantsBuilder.java | 47 +++++++++++ .../builder/constants/package-info.java | 8 ++ .../dessignpattern/builder/model/Netflix.java | 51 ++++++++++++ .../builder/model/Producto.java | 66 ++++++++++++++++ .../builder/model/Software.java | 79 +++++++++++++++++++ .../dessignpattern/builder/model/Spotify.java | 51 ++++++++++++ .../builder/model/package-info.java | 8 ++ .../dessignpattern/builder/package-info.java | 8 ++ .../dessignpattern/builder/BuilderTest.java | 75 ++++++++++++++++++ factory/build.gradle | 5 ++ .../dessignpattern/factory/Figura.java | 45 +++++++++++ .../dessignpattern/factory/FiguraFactory.java | 71 +++++++++++++++++ .../factory/constants/ConstantsFactory.java | 46 +++++++++++ .../factory/constants/package-info.java | 8 ++ .../factory/enumeration/FiguraTipoEnum.java | 42 ++++++++++ .../factory/enumeration/package-info.java | 8 ++ .../dessignpattern/factory/package-info.java | 8 ++ .../dessingpattern/factory/impl/Circulo.java | 49 ++++++++++++ .../dessingpattern/factory/impl/Cuadrado.java | 49 ++++++++++++ .../factory/impl/Triangulo.java | 49 ++++++++++++ .../factory/impl/package-info.java | 8 ++ .../factory/FiguraFactoryTest.java | 61 ++++++++++++++ settings.gradle | 5 +- singleton/build.gradle | 5 ++ .../singleton/SingletonObject.java | 68 ++++++++++++++++ .../singleton/package-info.java | 8 ++ .../singleton/SingletonTest.java | 47 +++++++++++ 35 files changed, 1068 insertions(+), 8 deletions(-) rename libraries.gradle => build-libraries.gradle (100%) create mode 100644 builder/build.gradle create mode 100644 builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/IngenieroSoftware.java create mode 100644 builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/constants/ConstantsBuilder.java create mode 100644 builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/constants/package-info.java create mode 100644 builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Netflix.java create mode 100644 builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Producto.java create mode 100644 builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Software.java create mode 100644 builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Spotify.java create mode 100644 builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/package-info.java create mode 100644 builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/package-info.java create mode 100644 builder/src/test/java/com/stephanoapiolaza/dessignpattern/builder/BuilderTest.java create mode 100644 factory/build.gradle create mode 100644 factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/Figura.java create mode 100644 factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/FiguraFactory.java create mode 100644 factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/constants/ConstantsFactory.java create mode 100644 factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/constants/package-info.java create mode 100644 factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/enumeration/FiguraTipoEnum.java create mode 100644 factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/enumeration/package-info.java create mode 100644 factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/package-info.java create mode 100644 factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/Circulo.java create mode 100644 factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/Cuadrado.java create mode 100644 factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/Triangulo.java create mode 100644 factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/package-info.java create mode 100644 factory/src/test/java/com/stephanoapiolaza/dessignpattern/factory/FiguraFactoryTest.java create mode 100644 singleton/build.gradle create mode 100644 singleton/src/main/java/com/stephanoapiolaza/dessignpattern/singleton/SingletonObject.java create mode 100644 singleton/src/main/java/com/stephanoapiolaza/dessignpattern/singleton/package-info.java create mode 100644 singleton/src/test/java/com/stephanoapiolaza/dessignpattern/singleton/SingletonTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 10f0c09..422b918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# 0.2.0(21-01-2018) + +### Features + +* **factory.method**: Se agrega patron creacional de clases. +* **singleton**: Se agrega patron creacional de objetos. +* **builder**: Se agrega patron creacional de objetos. + # 0.1.0(19-11-2017) ### Features diff --git a/abstract-factory/build.gradle b/abstract-factory/build.gradle index 1e7bfd1..8a25f45 100644 --- a/abstract-factory/build.gradle +++ b/abstract-factory/build.gradle @@ -1,4 +1,4 @@ -description = 'The Abstract Factory Example to Learn' +description = 'The Abstract Factory patron creacional de objetos' dependencies { diff --git a/build-config.gradle b/build-config.gradle index 536a30d..9dcb1c9 100644 --- a/build-config.gradle +++ b/build-config.gradle @@ -6,10 +6,13 @@ Included from: "${rootProject.projectDir}/build.gradle" ============================================================================ */ + +// No se modifica versionn del proyecto, hasta externalizar en nexus o artifactory +version = "0.2.0" + subprojects { - group = "com.sapiolaza.dessignpattern" - // No se modifica versionn del proyecto, hasta externalizar en nexus o artifactory - version = "0.1.0" + group = "com.stephanoapiolaza.dessignpattern" + targetCompatibility = '1.8' } diff --git a/build-java.gradle b/build-java.gradle index 0b2bf01..f6cbed2 100644 --- a/build-java.gradle +++ b/build-java.gradle @@ -8,9 +8,8 @@ */ subprojects { + apply plugin: 'java' - - targetCompatibility = '1.8' /* Setup UTF-8 for compile AND test compilation*/ [ compileJava, compileTestJava ]*.options*.encoding = 'UTF-8' diff --git a/libraries.gradle b/build-libraries.gradle similarity index 100% rename from libraries.gradle rename to build-libraries.gradle diff --git a/build.gradle b/build.gradle index 61aa911..4779f53 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { } allprojects{ - apply from: "${rootProject.projectDir}/libraries.gradle" + apply from: "${rootProject.projectDir}/build-libraries.gradle" } /* -------------------------------- */ diff --git a/builder/build.gradle b/builder/build.gradle new file mode 100644 index 0000000..6d5b2e4 --- /dev/null +++ b/builder/build.gradle @@ -0,0 +1,5 @@ +description = 'The Builder patron creacional de objetos' + +dependencies { + +} diff --git a/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/IngenieroSoftware.java b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/IngenieroSoftware.java new file mode 100644 index 0000000..e74a42e --- /dev/null +++ b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/IngenieroSoftware.java @@ -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(); + } + +} diff --git a/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/constants/ConstantsBuilder.java b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/constants/ConstantsBuilder.java new file mode 100644 index 0000000..766b68b --- /dev/null +++ b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/constants/ConstantsBuilder.java @@ -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() {} + +} diff --git a/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/constants/package-info.java b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/constants/package-info.java new file mode 100644 index 0000000..722b64e --- /dev/null +++ b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/constants/package-info.java @@ -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; \ No newline at end of file diff --git a/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Netflix.java b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Netflix.java new file mode 100644 index 0000000..198b3b8 --- /dev/null +++ b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Netflix.java @@ -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); + } + +} diff --git a/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Producto.java b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Producto.java new file mode 100644 index 0000000..54167ea --- /dev/null +++ b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Producto.java @@ -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(); + +} diff --git a/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Software.java b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Software.java new file mode 100644 index 0000000..6b8de7d --- /dev/null +++ b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Software.java @@ -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; + } + +} diff --git a/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Spotify.java b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Spotify.java new file mode 100644 index 0000000..6bd18c1 --- /dev/null +++ b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/Spotify.java @@ -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 Spotify + * + * @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 Spotify extends Producto{ + + @Override + public void setLenguaje() { + super.software.lenguaje(ConstantsBuilder.LENGUAJE_SPOTIFY); + } + + @Override + public void setCantidadUsuarios() { + super.software.cantidadUsuarios(ConstantsBuilder.CANT_USER_SPOTIFY); + } + +} diff --git a/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/package-info.java b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/package-info.java new file mode 100644 index 0000000..d21ad38 --- /dev/null +++ b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/model/package-info.java @@ -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.builder.model; \ No newline at end of file diff --git a/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/package-info.java b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/package-info.java new file mode 100644 index 0000000..8b8a06b --- /dev/null +++ b/builder/src/main/java/com/stephanoapiolaza/dessignpattern/builder/package-info.java @@ -0,0 +1,8 @@ +/** + * Paquete de representacion del patron de disenno builder + * + * @version 1.0 - 21-01-2018 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +package com.stephanoapiolaza.dessignpattern.builder; \ No newline at end of file diff --git a/builder/src/test/java/com/stephanoapiolaza/dessignpattern/builder/BuilderTest.java b/builder/src/test/java/com/stephanoapiolaza/dessignpattern/builder/BuilderTest.java new file mode 100644 index 0000000..a3b9a8a --- /dev/null +++ b/builder/src/test/java/com/stephanoapiolaza/dessignpattern/builder/BuilderTest.java @@ -0,0 +1,75 @@ +/* + * 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 static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +import com.stephanoapiolaza.dessignpattern.builder.constants.ConstantsBuilder; +import com.stephanoapiolaza.dessignpattern.builder.model.Netflix; +import com.stephanoapiolaza.dessignpattern.builder.model.Software; +import com.stephanoapiolaza.dessignpattern.builder.model.Spotify; + +/** + * Permite validar el patron builder + * + * 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 BuilderTest { + + private IngenieroSoftware ingeniero; + + @Before + public void setup() { + // se llama al director o ingeniero + ingeniero = new IngenieroSoftware(); + } + + @Test + public void getSoftware_isSpotify() { + // se le asigna un producto a crear + ingeniero.setProducto(new Spotify()); + ingeniero.crearProducto(); + Software software = ingeniero.getProducto(); + assertEquals(ConstantsBuilder.LENGUAJE_SPOTIFY, software.getLenguaje()); + } + + @Test + public void getSoftware_isNetflix() { + // se le asigna un producto a crear + ingeniero.setProducto(new Netflix()); + ingeniero.crearProducto(); + Software software = ingeniero.getProducto(); + assertEquals(ConstantsBuilder.LENGUAJE_NETFLIX, software.getLenguaje()); + } + +} diff --git a/factory/build.gradle b/factory/build.gradle new file mode 100644 index 0000000..39dcdf4 --- /dev/null +++ b/factory/build.gradle @@ -0,0 +1,5 @@ +description = 'The Factory Method patron creacional de clase' + +dependencies { + +} diff --git a/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/Figura.java b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/Figura.java new file mode 100644 index 0000000..ad74846 --- /dev/null +++ b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/Figura.java @@ -0,0 +1,45 @@ +/* + * 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.factory; + +/** + * Clase que representa el patron de disenno factory + * Interfaz de comunicacion con la Factoria, + * esto permite polimorfismo para que un objeto pueda mutar + * si es que provienen de la misma jerarquia (opcional) + * + * @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 interface Figura { + + /** + * Metodo heredado que permite obtener un texto de la figura geometrica a que pertenece + */ + public String getDibujo(); + +} diff --git a/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/FiguraFactory.java b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/FiguraFactory.java new file mode 100644 index 0000000..a2b644f --- /dev/null +++ b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/FiguraFactory.java @@ -0,0 +1,71 @@ +/* + * 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.factory; + +import com.stephanoapiolaza.dessignpattern.factory.enumeration.FiguraTipoEnum; +import com.stephanoapiolaza.dessingpattern.factory.impl.Circulo; +import com.stephanoapiolaza.dessingpattern.factory.impl.Cuadrado; +import com.stephanoapiolaza.dessingpattern.factory.impl.Triangulo; + +/** + * Clase que representa el patron de disenno singleton + * 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 + * @version 1.0 - 21-01-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class FiguraFactory { + + /** + * Constructor Privado + */ + private FiguraFactory() { + + } + + /** + * Retorna un tipo de figura disponible + * @param tipoFigura enum con los tipos de figura disponibilizados + * @return tipo de figura solicitada + */ + public static Figura getFigura(FiguraTipoEnum tipoFigura) { + if ( null == tipoFigura ) { + return null; + } + if ( tipoFigura.equals(FiguraTipoEnum.CIRCULO) ) { + return new Circulo(); + } else if ( tipoFigura.equals(FiguraTipoEnum.CUADRADO) ) { + return new Cuadrado(); + } else if ( tipoFigura.equals(FiguraTipoEnum.TRIANGULO) ) { + return new Triangulo(); + } + return null; + } + +} diff --git a/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/constants/ConstantsFactory.java b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/constants/ConstantsFactory.java new file mode 100644 index 0000000..391450a --- /dev/null +++ b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/constants/ConstantsFactory.java @@ -0,0 +1,46 @@ +/* + * 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.factory.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 ConstantsFactory { + + 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 ConstantsFactory() {} + +} diff --git a/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/constants/package-info.java b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/constants/package-info.java new file mode 100644 index 0000000..70e2038 --- /dev/null +++ b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/constants/package-info.java @@ -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.factory.constants; \ No newline at end of file diff --git a/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/enumeration/FiguraTipoEnum.java b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/enumeration/FiguraTipoEnum.java new file mode 100644 index 0000000..5c8709d --- /dev/null +++ b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/enumeration/FiguraTipoEnum.java @@ -0,0 +1,42 @@ +/* + * 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.factory.enumeration; + +/** + * Clase que representa todos los posibles tipos + * de figura geometricas a utilizar + * + * @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 enum FiguraTipoEnum { + + CIRCULO, + CUADRADO, + TRIANGULO; + +} diff --git a/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/enumeration/package-info.java b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/enumeration/package-info.java new file mode 100644 index 0000000..875a6b5 --- /dev/null +++ b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/enumeration/package-info.java @@ -0,0 +1,8 @@ +/** + * Paquete de multiples constantes definidas en enumeration + * + * @version 1.0 - 21-01-2018 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +package com.stephanoapiolaza.dessignpattern.factory.enumeration; \ No newline at end of file diff --git a/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/package-info.java b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/package-info.java new file mode 100644 index 0000000..e492f25 --- /dev/null +++ b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/package-info.java @@ -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.factory; \ No newline at end of file diff --git a/factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/Circulo.java b/factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/Circulo.java new file mode 100644 index 0000000..e83541b --- /dev/null +++ b/factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/Circulo.java @@ -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.factory.impl; + +import com.stephanoapiolaza.dessignpattern.factory.Figura; +import com.stephanoapiolaza.dessignpattern.factory.constants.ConstantsFactory; + +/** + * Clase que representa el patron de disenno factory + * Modelo con comunicacion con la interfaz + * + * @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 Circulo implements Figura{ + + /** + * Metodo que retorna el tipo de dibujo a que pertenece + */ + @Override + public String getDibujo() { + return ConstantsFactory.OUTPUT_CIRCLE; + } + +} diff --git a/factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/Cuadrado.java b/factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/Cuadrado.java new file mode 100644 index 0000000..744edba --- /dev/null +++ b/factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/Cuadrado.java @@ -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.factory.impl; + +import com.stephanoapiolaza.dessignpattern.factory.Figura; +import com.stephanoapiolaza.dessignpattern.factory.constants.ConstantsFactory; + +/** + * Clase que representa el patron de disenno factory + * Modelo con comunicacion con la interfaz + * + * @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 Cuadrado implements Figura{ + + /** + * Metodo que retorna el tipo de dibujo a que pertenece + */ + @Override + public String getDibujo() { + return ConstantsFactory.OUTPUT_SQUARE; + } + +} diff --git a/factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/Triangulo.java b/factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/Triangulo.java new file mode 100644 index 0000000..3977655 --- /dev/null +++ b/factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/Triangulo.java @@ -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.factory.impl; + +import com.stephanoapiolaza.dessignpattern.factory.Figura; +import com.stephanoapiolaza.dessignpattern.factory.constants.ConstantsFactory; + +/** + * Clase que representa el patron de disenno factory + * Modelo con comunicacion con la interfaz + * + * @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 Triangulo implements Figura{ + + /** + * Metodo que retorna el tipo de dibujo a que pertenece + */ + @Override + public String getDibujo() { + return ConstantsFactory.OUTPUT_TRIANGLE; + } + +} diff --git a/factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/package-info.java b/factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/package-info.java new file mode 100644 index 0000000..74f03e9 --- /dev/null +++ b/factory/src/main/java/com/stephanoapiolaza/dessingpattern/factory/impl/package-info.java @@ -0,0 +1,8 @@ +/** + * Paquete de implementaciones de Figuras Geometricas + * + * @version 1.0 - 21-01-2018 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +package com.stephanoapiolaza.dessingpattern.factory.impl; \ No newline at end of file diff --git a/factory/src/test/java/com/stephanoapiolaza/dessignpattern/factory/FiguraFactoryTest.java b/factory/src/test/java/com/stephanoapiolaza/dessignpattern/factory/FiguraFactoryTest.java new file mode 100644 index 0000000..2c10853 --- /dev/null +++ b/factory/src/test/java/com/stephanoapiolaza/dessignpattern/factory/FiguraFactoryTest.java @@ -0,0 +1,61 @@ +/* + * 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.factory; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.stephanoapiolaza.dessignpattern.factory.enumeration.FiguraTipoEnum; +import com.stephanoapiolaza.dessingpattern.factory.impl.Circulo; +import com.stephanoapiolaza.dessingpattern.factory.impl.Cuadrado; +import com.stephanoapiolaza.dessingpattern.factory.impl.Triangulo; + +/** + * Clase que permite validar el patron Factory + * + * @see {@link https://www.tutorialspoint.com/design_pattern/singleton_pattern.htm} + * @category Patrones Creacionales + * @version 1.0 - 21-01-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class FiguraFactoryTest { + + @Test + public void getFigura_isCirculo() { + assertEquals(new Circulo().getDibujo(), FiguraFactory.getFigura(FiguraTipoEnum.CIRCULO).getDibujo()); + } + + @Test + public void getFigura_isCuadrado() { + assertEquals(new Cuadrado().getDibujo(), FiguraFactory.getFigura(FiguraTipoEnum.CUADRADO).getDibujo()); + } + + @Test + public void getFigura_isTriangulo() { + assertEquals(new Triangulo().getDibujo(), FiguraFactory.getFigura(FiguraTipoEnum.TRIANGULO).getDibujo()); + } + +} diff --git a/settings.gradle b/settings.gradle index 7bde4b2..3087345 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,6 +10,9 @@ // To declare projects as part of a multi-project build use the 'include' method -include 'abstract-factory' +include 'abstract-factory'; +include 'singleton'; +include 'builder'; +include 'factory'; rootProject.name = 'dessign-pattern' diff --git a/singleton/build.gradle b/singleton/build.gradle new file mode 100644 index 0000000..1b7a89f --- /dev/null +++ b/singleton/build.gradle @@ -0,0 +1,5 @@ +description = 'The Singleton patron creacional de objetos' + +dependencies { + +} diff --git a/singleton/src/main/java/com/stephanoapiolaza/dessignpattern/singleton/SingletonObject.java b/singleton/src/main/java/com/stephanoapiolaza/dessignpattern/singleton/SingletonObject.java new file mode 100644 index 0000000..2de09fd --- /dev/null +++ b/singleton/src/main/java/com/stephanoapiolaza/dessignpattern/singleton/SingletonObject.java @@ -0,0 +1,68 @@ +/* + * 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.singleton; + +/** + * Clase que representa el patron de disenno singleton + * 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 - Objetos + * @version 1.0 - 21-01-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class SingletonObject { + + // Se crea una variable estatica, esto permite que los valores sean compartidos dentro de instancias de esta misma clase + private static SingletonObject instance; + private static final String[] DATA_CACHE = {"Cache 1", "Cache 2", "Cache 3"}; + + /** + * Se esconde el constructor, porque se debe llamar a getInstance() (sino no tendria sentido) + */ + private SingletonObject() {} + + /** + * Se crea una instancia unica para esta clase, esto permite reutilizacion + * @return instancia unica de la clase + */ + public static SingletonObject getInstance() { + if ( null == instance ) { + instance = new SingletonObject(); + } + return instance; + } + + /** + * Metodo de prueba de patron singleton, muy util para clases de caching + * @return datos en cache + */ + public String[] getDataInCache() { + return DATA_CACHE; + } + +} diff --git a/singleton/src/main/java/com/stephanoapiolaza/dessignpattern/singleton/package-info.java b/singleton/src/main/java/com/stephanoapiolaza/dessignpattern/singleton/package-info.java new file mode 100644 index 0000000..699ab2b --- /dev/null +++ b/singleton/src/main/java/com/stephanoapiolaza/dessignpattern/singleton/package-info.java @@ -0,0 +1,8 @@ +/** + * Paquete de representacion del patron de disenno singleton + * + * @version 1.0 - 21-01-2018 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +package com.stephanoapiolaza.dessignpattern.singleton; \ No newline at end of file diff --git a/singleton/src/test/java/com/stephanoapiolaza/dessignpattern/singleton/SingletonTest.java b/singleton/src/test/java/com/stephanoapiolaza/dessignpattern/singleton/SingletonTest.java new file mode 100644 index 0000000..4ecd100 --- /dev/null +++ b/singleton/src/test/java/com/stephanoapiolaza/dessignpattern/singleton/SingletonTest.java @@ -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.singleton; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +import com.stephanoapiolaza.dessignpattern.singleton.SingletonObject; + +/** + * Permite Validar el patron singleton + * + * @version 1.0 - 21-01-18 + * @author Stephano.Apiolaza + * + */ +public class SingletonTest { + + @Test + public void getDataInCache_isNotNull() { + assertNotNull(SingletonObject.getInstance().getDataInCache()); + } + +} + From ae302a52d36e327b76deb3afcefd46eee4753a11 Mon Sep 17 00:00:00 2001 From: Stephano Apiolaza Date: Sat, 27 Jan 2018 23:40:49 -0300 Subject: [PATCH 2/4] DP01 - feat(prototype): Se agrega patron creacional de objetos --- CHANGELOG.md | 6 + build-config.gradle | 5 +- .../dessignpattern/factory/FiguraFactory.java | 6 +- prototype/build.gradle | 5 + .../dessignpattern/prototype/Figura.java | 79 ++++++++++++ .../dessignpattern/prototype/FiguraCache.java | 117 ++++++++++++++++++ .../constants/ConstantsPrototype.java | 50 ++++++++ .../prototype/constants/package-info.java | 8 ++ .../prototype/package-info.java | 8 ++ .../prototype/impl/Circulo.java | 49 ++++++++ .../prototype/impl/Cuadrado.java | 49 ++++++++ .../prototype/impl/Triangulo.java | 49 ++++++++ .../prototype/impl/package-info.java | 8 ++ .../prototype/PrototypeTest.java | 67 ++++++++++ settings.gradle | 1 + 15 files changed, 501 insertions(+), 6 deletions(-) create mode 100644 prototype/build.gradle create mode 100644 prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/Figura.java create mode 100644 prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/FiguraCache.java create mode 100644 prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/constants/ConstantsPrototype.java create mode 100644 prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/constants/package-info.java create mode 100644 prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/package-info.java create mode 100644 prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Circulo.java create mode 100644 prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Cuadrado.java create mode 100644 prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Triangulo.java create mode 100644 prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/package-info.java create mode 100644 prototype/src/test/java/com/stephanoapiolaza/dessignpattern/prototype/PrototypeTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 422b918..8ebab82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/build-config.gradle b/build-config.gradle index 9dcb1c9..4ed4561 100644 --- a/build-config.gradle +++ b/build-config.gradle @@ -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 { diff --git a/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/FiguraFactory.java b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/FiguraFactory.java index a2b644f..c46c075 100644 --- a/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/FiguraFactory.java +++ b/factory/src/main/java/com/stephanoapiolaza/dessignpattern/factory/FiguraFactory.java @@ -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 * diff --git a/prototype/build.gradle b/prototype/build.gradle new file mode 100644 index 0000000..ac8ba31 --- /dev/null +++ b/prototype/build.gradle @@ -0,0 +1,5 @@ +description = 'The Prototype patron creacional de objetos' + +dependencies { + +} diff --git a/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/Figura.java b/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/Figura.java new file mode 100644 index 0000000..6187df1 --- /dev/null +++ b/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/Figura.java @@ -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; + } + + + +} diff --git a/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/FiguraCache.java b/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/FiguraCache.java new file mode 100644 index 0000000..d839056 --- /dev/null +++ b/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/FiguraCache.java @@ -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 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); + } + +} diff --git a/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/constants/ConstantsPrototype.java b/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/constants/ConstantsPrototype.java new file mode 100644 index 0000000..d615206 --- /dev/null +++ b/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/constants/ConstantsPrototype.java @@ -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() {} + +} diff --git a/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/constants/package-info.java b/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/constants/package-info.java new file mode 100644 index 0000000..99aae41 --- /dev/null +++ b/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/constants/package-info.java @@ -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; \ No newline at end of file diff --git a/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/package-info.java b/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/package-info.java new file mode 100644 index 0000000..d57111d --- /dev/null +++ b/prototype/src/main/java/com/stephanoapiolaza/dessignpattern/prototype/package-info.java @@ -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; \ No newline at end of file diff --git a/prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Circulo.java b/prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Circulo.java new file mode 100644 index 0000000..96f7733 --- /dev/null +++ b/prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Circulo.java @@ -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; + } + +} diff --git a/prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Cuadrado.java b/prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Cuadrado.java new file mode 100644 index 0000000..26306a3 --- /dev/null +++ b/prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Cuadrado.java @@ -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 Cuadrado extends Figura{ + + /** + * Metodo que retorna el tipo de dibujo a que pertenece + */ + @Override + public String getDibujo() { + return ConstantsPrototype.OUTPUT_SQUARE; + } + +} diff --git a/prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Triangulo.java b/prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Triangulo.java new file mode 100644 index 0000000..c0c4089 --- /dev/null +++ b/prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/Triangulo.java @@ -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 Triangulo extends Figura{ + + /** + * Metodo que retorna el tipo de dibujo a que pertenece + */ + @Override + public String getDibujo() { + return ConstantsPrototype.OUTPUT_TRIANGLE; + } + +} diff --git a/prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/package-info.java b/prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/package-info.java new file mode 100644 index 0000000..9d0e0b5 --- /dev/null +++ b/prototype/src/main/java/com/stephanoapiolaza/dessingpattern/prototype/impl/package-info.java @@ -0,0 +1,8 @@ +/** + * Paquete de implementaciones de Figuras Geometricas + * + * @version 1.0 - 21-01-2018 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +package com.stephanoapiolaza.dessingpattern.prototype.impl; \ No newline at end of file diff --git a/prototype/src/test/java/com/stephanoapiolaza/dessignpattern/prototype/PrototypeTest.java b/prototype/src/test/java/com/stephanoapiolaza/dessignpattern/prototype/PrototypeTest.java new file mode 100644 index 0000000..0069f8e --- /dev/null +++ b/prototype/src/test/java/com/stephanoapiolaza/dessignpattern/prototype/PrototypeTest.java @@ -0,0 +1,67 @@ +/* + * 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 static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +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 permite validar el patron prototype + * + * @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 PrototypeTest { + + @Before + public void setup() { + FiguraCache.loadCache(); + } + + @Test + public void getFigura_isCirculo() { + assertEquals(new Circulo().getDibujo(), FiguraCache.getFigura(ConstantsPrototype.ID_CIRCLE).getDibujo()); + } + + @Test + public void getFigura_isCuadrado() { + assertEquals(new Cuadrado().getDibujo(), FiguraCache.getFigura(ConstantsPrototype.ID_SQUARE).getDibujo()); + } + + @Test + public void getFigura_isTriangulo() { + assertEquals(new Triangulo().getDibujo(), FiguraCache.getFigura(ConstantsPrototype.ID_TRIANGLE).getDibujo()); + } + +} diff --git a/settings.gradle b/settings.gradle index 3087345..c2f0697 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,5 +14,6 @@ include 'abstract-factory'; include 'singleton'; include 'builder'; include 'factory'; +include 'prototype'; rootProject.name = 'dessign-pattern' From 6e061a835b7e59e4e3ffbeaba5c7992164c4e8f8 Mon Sep 17 00:00:00 2001 From: Stephano Apiolaza Date: Mon, 30 Apr 2018 18:19:51 -0300 Subject: [PATCH 3/4] DP01 - feat(abstract.factory): Se agrega patron creacional de objetos --- CHANGELOG.md | 6 ++ README.md | 13 +-- .../abstractfactory/AbstractFactory.java | 75 ++++++++++++++++++ .../abstractfactory/color/Color.java | 45 +++++++++++ .../abstractfactory/color/ColorFactory.java | 78 ++++++++++++++++++ .../abstractfactory/color/package-info.java | 8 ++ .../constants/ConstantsFactory.java | 52 ++++++++++++ .../constants/package-info.java | 8 ++ .../enumeration/ColorTipoEnum.java | 41 ++++++++++ .../enumeration/FiguraTipoEnum.java | 42 ++++++++++ .../enumeration/package-info.java | 8 ++ .../abstractfactory/package-info.java | 8 ++ .../abstractfactory/shape/Figura.java | 45 +++++++++++ .../abstractfactory/shape/FiguraFactory.java | 79 +++++++++++++++++++ .../abstractfactory/shape/package-info.java | 8 ++ .../abstractfactory/color/impl/Azul.java | 49 ++++++++++++ .../abstractfactory/color/impl/Rojo.java | 49 ++++++++++++ .../abstractfactory/color/impl/Verde.java | 49 ++++++++++++ .../color/impl/package-info.java | 8 ++ .../abstractfactory/shape/impl/Circulo.java | 49 ++++++++++++ .../abstractfactory/shape/impl/Cuadrado.java | 49 ++++++++++++ .../abstractfactory/shape/impl/Triangulo.java | 49 ++++++++++++ .../shape/impl/package-info.java | 8 ++ .../factory/AbstractFactoryTest.java | 59 ++++++++++++++ build-config.gradle | 2 +- 25 files changed, 880 insertions(+), 7 deletions(-) create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/AbstractFactory.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/Color.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/ColorFactory.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/package-info.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/constants/ConstantsFactory.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/constants/package-info.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/ColorTipoEnum.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/FiguraTipoEnum.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/package-info.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/package-info.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/shape/Figura.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/shape/FiguraFactory.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/shape/package-info.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/Azul.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/Rojo.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/Verde.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/package-info.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/Circulo.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/Cuadrado.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/Triangulo.java create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/package-info.java create mode 100644 abstract-factory/src/test/java/com/stephanoapiolaza/dessignpattern/factory/AbstractFactoryTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ebab82..8723bf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.4.0(30-04-2018) + +### Features + +* **abstract.factory**: Se agrega patron creacional de objeto. + # 0.3.0(27-01-2018) ### Features diff --git a/README.md b/README.md index a175687..c4591af 100644 --- a/README.md +++ b/README.md @@ -35,18 +35,19 @@ Si deseas crear objetos puedes basarte en estos: ### Clases -* **Factory Method** +* **Factory Method**: permite crear objetos dinamicamente, donde retorna el solicitado por parametro. ### Objetos -* **Abstract Factory** -* **Builder** -* **Prototype** -* **Singleton** +* **Abstract Factory**: permite la creacion de factoria dinamicamente, donde se retorna la solicitada por parametro. (capa adicional al patron factory) +* **Builder**: permite crear objetos complejos, donde un orquestador o clase que se encarga de construir el elemento, lo fabrica paso a paso. Ademas, se suele atribuir a este patron la reduccion de complejidad de los +pojo (clases con get y set, solo tiene el dominio o campos de una seccion del modelo) al annadir metodos estaticos concatenables que retornar la misma instancia para modificar los atributos privados. +* **Prototype**: permite optimizar la creacion de objetos a traves de un proceso de clonacion, solo se requiere implementar la interfaz cloneable y sobreescribir el metodo clone. +* **Singleton**: permite asegurar una unica instancia por objetos, reutilizandolo a lo largo de una aplicacion. ## Patrones Estructurales -### Objetos +### Objetoss * **Adapter** * **Bridge** diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/AbstractFactory.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/AbstractFactory.java new file mode 100644 index 0000000..687956b --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/AbstractFactory.java @@ -0,0 +1,75 @@ +/* + * 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.abstractfactory; + +import com.stephanoapiolaza.dessignpattern.abstractfactory.color.Color; +import com.stephanoapiolaza.dessignpattern.abstractfactory.color.ColorFactory; +import com.stephanoapiolaza.dessignpattern.abstractfactory.enumeration.ColorTipoEnum; +import com.stephanoapiolaza.dessignpattern.abstractfactory.enumeration.FiguraTipoEnum; +import com.stephanoapiolaza.dessignpattern.abstractfactory.shape.Figura; +import com.stephanoapiolaza.dessignpattern.abstractfactory.shape.FiguraFactory; + +/** + * Interfaz que representa el patron de disenno abstract 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/abstract_factory_pattern.htm} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-04-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public abstract class AbstractFactory { + + /** + * Permite crear una instancia de tipo color + * @param color solicitado + * @return instancia solicitada + */ + public abstract Color getColor(ColorTipoEnum color); + + /** + * Permite crear una instancia de tipo figura + * @param shape solicitado + * @return instancia solicitada + */ + public abstract Figura getShape(FiguraTipoEnum shape); + + /** + * Permite crear factorias + * @param choice factoria a crear + * @return factoria solicitada + */ + public static AbstractFactory getFactory(String choice) { + if ( choice.equals("SHAPE")) { + return new FiguraFactory(); + } else if ( choice.equals("COLOR")) { + return new ColorFactory(); + } + return null; + } + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/Color.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/Color.java new file mode 100644 index 0000000..7133510 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/Color.java @@ -0,0 +1,45 @@ +/* + * 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.abstractfactory.color; + +/** + * Clase que representa el patron de disenno abstract factory + * Interfaz de comunicacion con la Factoria, + * esto permite polimorfismo para que un objeto pueda mutar + * si es que provienen de la misma jerarquia (opcional) + * + * @see {@link https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-01-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public interface Color { + + /** + * Metodo heredado que permite obtener un texto del color al que pertenece + */ + public String getColor(); + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/ColorFactory.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/ColorFactory.java new file mode 100644 index 0000000..e364460 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/ColorFactory.java @@ -0,0 +1,78 @@ +/* + * 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.abstractfactory.color; + +import com.stephanoapiolaza.dessignpattern.abstractfactory.AbstractFactory; +import com.stephanoapiolaza.dessignpattern.abstractfactory.enumeration.ColorTipoEnum; +import com.stephanoapiolaza.dessignpattern.abstractfactory.enumeration.FiguraTipoEnum; +import com.stephanoapiolaza.dessignpattern.abstractfactory.shape.Figura; +import com.stephanoapiolaza.dessingpattern.abstractfactory.color.impl.Azul; +import com.stephanoapiolaza.dessingpattern.abstractfactory.color.impl.Rojo; +import com.stephanoapiolaza.dessingpattern.abstractfactory.color.impl.Verde; + +/** + * Clase que representa el patron de disenno abstract 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/abstract_factory_pattern.htms} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-04-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class ColorFactory extends AbstractFactory { + + /** + * Retorna un color disponible + * @param color solicitado + * @return instancia del color + */ + @Override + public Color getColor(ColorTipoEnum color) { + if ( null == color ) { + return null; + } + if ( color.equals(ColorTipoEnum.AZUL) ) { + return new Azul(); + } else if ( color.equals(ColorTipoEnum.VERDE) ) { + return new Verde(); + } else if ( color.equals(ColorTipoEnum.ROJO) ) { + return new Rojo(); + } + return null; + } + + /** + * Retorna una figura disponible + * @param shape solicitado + * @return null porque este factory solo permite crear colores + */ + @Override + public Figura getShape(FiguraTipoEnum shape) { + return null; + } + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/package-info.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/package-info.java new file mode 100644 index 0000000..3c9e9af --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/package-info.java @@ -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.abstractfactory.color; \ No newline at end of file diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/constants/ConstantsFactory.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/constants/ConstantsFactory.java new file mode 100644 index 0000000..a0a0da2 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/constants/ConstantsFactory.java @@ -0,0 +1,52 @@ +/* + * 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.abstractfactory.constants; + +/** + * Clase con constantes para las salidas del dibujo + * + * @see {@link https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-04-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class ConstantsFactory { + + /* SHAPE */ + 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"; + + /* COLORS */ + public static final String OUTPUT_BLUE = "Yo soy el color azul"; + public static final String OUTPUT_GREEN = "Yo soy el color verde"; + public static final String OUTPUT_RED = "Yo soy el color rojo"; + + /** + * Constructor oculto + */ + private ConstantsFactory() {} + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/constants/package-info.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/constants/package-info.java new file mode 100644 index 0000000..6ccc398 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/constants/package-info.java @@ -0,0 +1,8 @@ +/** + * Paquete de constantes para su reutilizacion + * + * @version 1.0 - 30-04-2018 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +package com.stephanoapiolaza.dessignpattern.abstractfactory.constants; \ No newline at end of file diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/ColorTipoEnum.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/ColorTipoEnum.java new file mode 100644 index 0000000..0aeb5f8 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/ColorTipoEnum.java @@ -0,0 +1,41 @@ +/* + * 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.abstractfactory.enumeration; + +/** + * Clase que representa todos los posibles colores basicos disponibles en la aplicacion + * + * @see {@link https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-04-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public enum ColorTipoEnum { + + AZUL, + ROJO, + VERDE; + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/FiguraTipoEnum.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/FiguraTipoEnum.java new file mode 100644 index 0000000..4f184b2 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/FiguraTipoEnum.java @@ -0,0 +1,42 @@ +/* + * 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.abstractfactory.enumeration; + +/** + * Clase que representa todos los posibles tipos + * de figura geometricas a utilizar + * + * @see {@link https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-04-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public enum FiguraTipoEnum { + + CIRCULO, + CUADRADO, + TRIANGULO; + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/package-info.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/package-info.java new file mode 100644 index 0000000..150031f --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/package-info.java @@ -0,0 +1,8 @@ +/** + * Paquete de multiples constantes definidas en enumeration + * + * @version 1.0 - 30-04-2018 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +package com.stephanoapiolaza.dessignpattern.abstractfactory.enumeration; \ No newline at end of file diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/package-info.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/package-info.java new file mode 100644 index 0000000..7fd7c13 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/package-info.java @@ -0,0 +1,8 @@ +/** + * Paquete de representacion del patron de disenno abstract factory + * + * @version 1.0 - 30-04-2018 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +package com.stephanoapiolaza.dessignpattern.abstractfactory; \ No newline at end of file diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/shape/Figura.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/shape/Figura.java new file mode 100644 index 0000000..9db3041 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/shape/Figura.java @@ -0,0 +1,45 @@ +/* + * 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.abstractfactory.shape; + +/** + * Clase que representa el patron de disenno factory + * Interfaz de comunicacion con la Factoria, + * esto permite polimorfismo para que un objeto pueda mutar + * si es que provienen de la misma jerarquia (opcional) + * + * @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 interface Figura { + + /** + * Metodo heredado que permite obtener un texto de la figura geometrica a que pertenece + */ + public String getDibujo(); + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/shape/FiguraFactory.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/shape/FiguraFactory.java new file mode 100644 index 0000000..7233fef --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/shape/FiguraFactory.java @@ -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.abstractfactory.shape; + +import com.stephanoapiolaza.dessignpattern.abstractfactory.AbstractFactory; +import com.stephanoapiolaza.dessignpattern.abstractfactory.color.Color; +import com.stephanoapiolaza.dessignpattern.abstractfactory.enumeration.ColorTipoEnum; +import com.stephanoapiolaza.dessignpattern.abstractfactory.enumeration.FiguraTipoEnum; +import com.stephanoapiolaza.dessignpattern.abstractfactory.shape.Figura; +import com.stephanoapiolaza.dessingpattern.abstractfactory.shape.impl.Circulo; +import com.stephanoapiolaza.dessingpattern.abstractfactory.shape.impl.Cuadrado; +import com.stephanoapiolaza.dessingpattern.abstractfactory.shape.impl.Triangulo; + +/** + * Clase que representa el patron de disenno abstract 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/abstract_factory_pattern.htms} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-04-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class FiguraFactory extends AbstractFactory { + + /** + * Retorna un color disponible + * @param color solicitado + * @return null, porque este factory solo es para crear figuras + */ + @Override + public Color getColor(ColorTipoEnum color) { + return null; + } + + /** + * Retorna un tipo de figura disponible + * @param tipoFigura enum con los tipos de figura disponibilizados + * @return tipo de figura solicitada + */ + @Override + public Figura getShape(FiguraTipoEnum shape) { + if ( null == shape ) { + return null; + } + if ( shape.equals(FiguraTipoEnum.CIRCULO) ) { + return new Circulo(); + } else if ( shape.equals(FiguraTipoEnum.CUADRADO) ) { + return new Cuadrado(); + } else if ( shape.equals(FiguraTipoEnum.TRIANGULO) ) { + return new Triangulo(); + } + return null; + } + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/shape/package-info.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/shape/package-info.java new file mode 100644 index 0000000..7afeacc --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/shape/package-info.java @@ -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.abstractfactory.shape; \ No newline at end of file diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/Azul.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/Azul.java new file mode 100644 index 0000000..9adeabb --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/Azul.java @@ -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.abstractfactory.color.impl; + +import com.stephanoapiolaza.dessignpattern.abstractfactory.color.Color; +import com.stephanoapiolaza.dessignpattern.abstractfactory.constants.ConstantsFactory; + +/** + * Clase que representa el patron de disenno abstract factory + * Modelo con comunicacion con la interfaz + * + * @see {@link https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-04-2018 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class Azul implements Color { + + /** + * Metodo que retorna el color al que pertenece + */ + @Override + public String getColor() { + return ConstantsFactory.OUTPUT_BLUE; + } + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/Rojo.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/Rojo.java new file mode 100644 index 0000000..06dc44f --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/Rojo.java @@ -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.abstractfactory.color.impl; + +import com.stephanoapiolaza.dessignpattern.abstractfactory.color.Color; +import com.stephanoapiolaza.dessignpattern.abstractfactory.constants.ConstantsFactory; + +/** + * Clase que representa el patron de disenno abstract factory + * Modelo con comunicacion con la interfaz + * + * @see {@link https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-04-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class Rojo implements Color { + + /** + * Metodo que retorna el color al que pertenece + */ + @Override + public String getColor() { + return ConstantsFactory.OUTPUT_RED; + } + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/Verde.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/Verde.java new file mode 100644 index 0000000..01f01e9 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/Verde.java @@ -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.abstractfactory.color.impl; + +import com.stephanoapiolaza.dessignpattern.abstractfactory.color.Color; +import com.stephanoapiolaza.dessignpattern.abstractfactory.constants.ConstantsFactory; + +/** + * Clase que representa el patron de disenno abstract factory + * Modelo con comunicacion con la interfaz + * + * @see {@link https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-04-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class Verde implements Color { + + /** + * Metodo que retorna el color al que pertenece + */ + @Override + public String getColor() { + return ConstantsFactory.OUTPUT_GREEN; + } + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/package-info.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/package-info.java new file mode 100644 index 0000000..e808eb8 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/color/impl/package-info.java @@ -0,0 +1,8 @@ +/** + * Paquete de implementaciones de Colores Primarios + * + * @version 1.0 - 30-04-2018 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +package com.stephanoapiolaza.dessingpattern.abstractfactory.color.impl; \ No newline at end of file diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/Circulo.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/Circulo.java new file mode 100644 index 0000000..525a499 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/Circulo.java @@ -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.abstractfactory.shape.impl; + +import com.stephanoapiolaza.dessignpattern.abstractfactory.constants.ConstantsFactory; +import com.stephanoapiolaza.dessignpattern.abstractfactory.shape.Figura; + +/** + * Clase que representa el patron de disenno abstract factory + * Modelo con comunicacion con la interfaz + * + * @see {@link https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-04-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class Circulo implements Figura { + + /** + * Metodo que retorna el tipo de dibujo a que pertenece + */ + @Override + public String getDibujo() { + return ConstantsFactory.OUTPUT_CIRCLE; + } + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/Cuadrado.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/Cuadrado.java new file mode 100644 index 0000000..6aa1e22 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/Cuadrado.java @@ -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.abstractfactory.shape.impl; + +import com.stephanoapiolaza.dessignpattern.abstractfactory.constants.ConstantsFactory; +import com.stephanoapiolaza.dessignpattern.abstractfactory.shape.Figura; + +/** + * Clase que representa el patron de disenno abstract factory + * Modelo con comunicacion con la interfaz + * + * @see {@link https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-04-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class Cuadrado implements Figura { + + /** + * Metodo que retorna el tipo de dibujo a que pertenece + */ + @Override + public String getDibujo() { + return ConstantsFactory.OUTPUT_SQUARE; + } + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/Triangulo.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/Triangulo.java new file mode 100644 index 0000000..c820d06 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/Triangulo.java @@ -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.abstractfactory.shape.impl; + +import com.stephanoapiolaza.dessignpattern.abstractfactory.constants.ConstantsFactory; +import com.stephanoapiolaza.dessignpattern.abstractfactory.shape.Figura; + +/** + * Clase que representa el patron de disenno abstract factory + * Modelo con comunicacion con la interfaz + * + * @see {@link https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm} + * @category Patrones Creacionales - Clase + * @version 1.0 - 30-04-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class Triangulo implements Figura { + + /** + * Metodo que retorna el tipo de dibujo a que pertenece + */ + @Override + public String getDibujo() { + return ConstantsFactory.OUTPUT_TRIANGLE; + } + +} diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/package-info.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/package-info.java new file mode 100644 index 0000000..9c64385 --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessingpattern/abstractfactory/shape/impl/package-info.java @@ -0,0 +1,8 @@ +/** + * Paquete de implementaciones de Figuras Geometricas + * + * @version 1.0 - 30-04-2018 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +package com.stephanoapiolaza.dessingpattern.abstractfactory.shape.impl; \ No newline at end of file diff --git a/abstract-factory/src/test/java/com/stephanoapiolaza/dessignpattern/factory/AbstractFactoryTest.java b/abstract-factory/src/test/java/com/stephanoapiolaza/dessignpattern/factory/AbstractFactoryTest.java new file mode 100644 index 0000000..ec8eb15 --- /dev/null +++ b/abstract-factory/src/test/java/com/stephanoapiolaza/dessignpattern/factory/AbstractFactoryTest.java @@ -0,0 +1,59 @@ +/* + * 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.factory; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.stephanoapiolaza.dessignpattern.abstractfactory.AbstractFactory; +import com.stephanoapiolaza.dessignpattern.abstractfactory.enumeration.ColorTipoEnum; +import com.stephanoapiolaza.dessignpattern.abstractfactory.enumeration.FiguraTipoEnum; +import com.stephanoapiolaza.dessingpattern.abstractfactory.color.impl.Azul; +import com.stephanoapiolaza.dessingpattern.abstractfactory.shape.impl.Cuadrado; + +/** + * Clase que permite validar el patron Abstract Factory + * + * @see {@link https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm} + * @category Patrones Creacionales + * @version 1.0 - 30-04-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public class AbstractFactoryTest { + + @Test + public void getColor_isAzul() { + AbstractFactory factories = AbstractFactory.getFactory("COLOR"); + assertEquals(new Azul().getColor(), factories.getColor(ColorTipoEnum.AZUL).getColor()); + } + + @Test + public void getFigura_isCuadrado() { + AbstractFactory factories = AbstractFactory.getFactory("SHAPE"); + assertEquals(new Cuadrado().getDibujo(), factories.getShape(FiguraTipoEnum.CUADRADO).getDibujo()); + } + +} diff --git a/build-config.gradle b/build-config.gradle index 4ed4561..36ffa16 100644 --- a/build-config.gradle +++ b/build-config.gradle @@ -7,7 +7,7 @@ ============================================================================ */ -version = "0.3.0" +version = "0.4.0" subprojects { From 432964ea69814569555309367419d88ebebf103c Mon Sep 17 00:00:00 2001 From: Stephano Apiolaza Date: Wed, 2 May 2018 13:28:01 -0300 Subject: [PATCH 4/4] DP01 - chore(refactoring): Se evita magic strings --- .../abstractfactory/AbstractFactory.java | 7 ++-- .../enumeration/FactoryTipoEnum.java | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/FactoryTipoEnum.java diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/AbstractFactory.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/AbstractFactory.java index 687956b..4447855 100644 --- a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/AbstractFactory.java +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/AbstractFactory.java @@ -26,6 +26,7 @@ import com.stephanoapiolaza.dessignpattern.abstractfactory.color.Color; import com.stephanoapiolaza.dessignpattern.abstractfactory.color.ColorFactory; import com.stephanoapiolaza.dessignpattern.abstractfactory.enumeration.ColorTipoEnum; +import com.stephanoapiolaza.dessignpattern.abstractfactory.enumeration.FactoryTipoEnum; import com.stephanoapiolaza.dessignpattern.abstractfactory.enumeration.FiguraTipoEnum; import com.stephanoapiolaza.dessignpattern.abstractfactory.shape.Figura; import com.stephanoapiolaza.dessignpattern.abstractfactory.shape.FiguraFactory; @@ -63,10 +64,10 @@ public abstract class AbstractFactory { * @param choice factoria a crear * @return factoria solicitada */ - public static AbstractFactory getFactory(String choice) { - if ( choice.equals("SHAPE")) { + public static AbstractFactory getFactory(FactoryTipoEnum choice) { + if ( choice.equals(FactoryTipoEnum.SHAPE)) { return new FiguraFactory(); - } else if ( choice.equals("COLOR")) { + } else if ( choice.equals(FactoryTipoEnum.COLOR)) { return new ColorFactory(); } return null; diff --git a/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/FactoryTipoEnum.java b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/FactoryTipoEnum.java new file mode 100644 index 0000000..f9da01a --- /dev/null +++ b/abstract-factory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/FactoryTipoEnum.java @@ -0,0 +1,41 @@ +/* + * 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.abstractfactory.enumeration; + +/** + * Clase que representa todos los posibles tipos + * de factories a utilizar + * + * @see {@link https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm} + * @category Patrones Creacionales - Objeto + * @version 1.0 - 02-05-18 + * @author Stephano.Apiolaza - stephanoapiolaza@gmail.com + * + */ +public enum FactoryTipoEnum { + + SHAPE, + COLOR; + +}