Skip to content

Commit

Permalink
DP01 - feat(abstract.factory): Se agrega patron creacional de objetos
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephano Apiolaza authored and Stephano Apiolaza committed Apr 30, 2018
1 parent ae302a5 commit 6e061a8
Show file tree
Hide file tree
Showing 25 changed files with 880 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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();

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Paquete de representacion del patron de disenno factory
*
* @version 1.0 - 21-01-2018
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com
*
*/
package com.stephanoapiolaza.dessignpattern.abstractfactory.color;
Original file line number Diff line number Diff line change
@@ -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() {}

}
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;

}
Loading

0 comments on commit 6e061a8

Please sign in to comment.