Skip to content

Commit

Permalink
DP01 - feat(creational.pattern): Se agrega singleton, builder y facto…
Browse files Browse the repository at this point in the history
…ry patterns
  • Loading branch information
Stephano Apiolaza committed Jan 21, 2018
1 parent 7c97c35 commit ab61fad
Show file tree
Hide file tree
Showing 35 changed files with 1,068 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion abstract-factory/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
description = 'The Abstract Factory Example to Learn'
description = 'The Abstract Factory patron creacional de objetos'

dependencies {

Expand Down
9 changes: 6 additions & 3 deletions build-config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

}
3 changes: 1 addition & 2 deletions build-java.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
}

allprojects{
apply from: "${rootProject.projectDir}/libraries.gradle"
apply from: "${rootProject.projectDir}/build-libraries.gradle"
}

/* -------------------------------- */
Expand Down
5 changes: 5 additions & 0 deletions builder/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description = 'The Builder patron creacional de objetos'

dependencies {

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

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Paquete de constantes para su reutilizacion
*
* @version 1.0 - 21-01-2018
* @author Stephano.Apiolaza - stephanoapiolaza@gmail.com
*
*/
package com.stephanoapiolaza.dessignpattern.builder.constants;
Original file line number Diff line number Diff line change
@@ -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);
}

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* MIT License
*
* Copyright (c) [2018] [Stephano Apiolaza]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.stephanoapiolaza.dessignpattern.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;
}

}
Loading

0 comments on commit ab61fad

Please sign in to comment.