-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from stephanoapiolaza/features/integracion/crea…
…tional-pattern DP01 - feat(creational.pattern): Se agrega singleton, builder y facto…
- Loading branch information
Showing
70 changed files
with
2,484 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...ry/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/AbstractFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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.FactoryTipoEnum; | ||
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(FactoryTipoEnum choice) { | ||
if ( choice.equals(FactoryTipoEnum.SHAPE)) { | ||
return new FiguraFactory(); | ||
} else if ( choice.equals(FactoryTipoEnum.COLOR)) { | ||
return new ColorFactory(); | ||
} | ||
return null; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...actory/src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/Color.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/ColorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...src/main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/color/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Paquete de representacion del patron de disenno factory | ||
* | ||
* @version 1.0 - 21-01-2018 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
package com.stephanoapiolaza.dessignpattern.abstractfactory.color; |
52 changes: 52 additions & 0 deletions
52
.../java/com/stephanoapiolaza/dessignpattern/abstractfactory/constants/ConstantsFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() {} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...main/java/com/stephanoapiolaza/dessignpattern/abstractfactory/constants/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Paquete de constantes para su reutilizacion | ||
* | ||
* @version 1.0 - 30-04-2018 | ||
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com | ||
* | ||
*/ | ||
package com.stephanoapiolaza.dessignpattern.abstractfactory.constants; |
41 changes: 41 additions & 0 deletions
41
...n/java/com/stephanoapiolaza/dessignpattern/abstractfactory/enumeration/ColorTipoEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
|
||
} |
Oops, something went wrong.