Compare commits
2 Commits
567bf7b788
...
3dbd862047
| Author | SHA1 | Date | |
|---|---|---|---|
| 3dbd862047 | |||
| 1df2d39e29 |
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public interface IRepositorio<T>
|
||||
{
|
||||
|
||||
private List<T> almacen;
|
||||
|
||||
// Añade objetos al almacen
|
||||
public bool Add(T t);
|
||||
|
||||
// Modifica objetos del almacen
|
||||
public bool Mod(T t);
|
||||
|
||||
// Elimina objetos del almacen
|
||||
public bool Del(T t);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,20 @@
|
||||
namespace Modelo
|
||||
using System.Runtime;
|
||||
using Entidades;
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public class RepositorioProductos : IRepositorio<Producto>
|
||||
public sealed class RepositorioProductos : RepositorioSingleton<Producto, RepositorioProductos>
|
||||
{
|
||||
//Contructor Privado
|
||||
private RepositorioProductos()
|
||||
override public bool Add(Producto t)
|
||||
{
|
||||
almacen = new List<Producto>;
|
||||
}
|
||||
|
||||
// Singleton
|
||||
private static RepositorioProductos instancia;
|
||||
public static RepositorioProductos Instancia
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instancia == null) instancia = new RepositorioProductos();
|
||||
return instancia;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Add(Producto t)
|
||||
{
|
||||
bool ret;
|
||||
bool ret = false;
|
||||
|
||||
try
|
||||
{
|
||||
almacen.add(t);
|
||||
almacen.Add(t);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@@ -36,9 +22,9 @@
|
||||
return ret;
|
||||
}
|
||||
|
||||
public bool Mod(Producto t)
|
||||
override public bool Mod(Producto t)
|
||||
{
|
||||
bool ret;
|
||||
bool ret = false;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -46,7 +32,7 @@
|
||||
AModificar = t;
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@@ -54,17 +40,18 @@
|
||||
return ret;
|
||||
}
|
||||
|
||||
public bool Del(Producto t)
|
||||
override public bool Del(Producto t)
|
||||
{
|
||||
bool ret;
|
||||
bool ret = false;
|
||||
|
||||
try
|
||||
{
|
||||
var AEliminar = almacen.Find(x => x.Id == t.Id);
|
||||
almacen.remove(AEliminar);
|
||||
if (AEliminar == null) return ret;
|
||||
almacen.Remove(AEliminar);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
37
Modelo/RepositorioSingleton.cs
Normal file
37
Modelo/RepositorioSingleton.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public abstract class RepositorioSingleton<T, J>
|
||||
where J : new()
|
||||
{
|
||||
|
||||
protected List<T> almacen;
|
||||
|
||||
//es protected para que solo se pueda llamar desde
|
||||
//las clases que implementen a esta clase
|
||||
protected RepositorioSingleton() {
|
||||
almacen = new List<T>();
|
||||
}
|
||||
|
||||
// Singleton thread-safe por si quiero usar "Parallel"
|
||||
private static J instance = new J();
|
||||
public static J Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
// Añade objetos al almacen
|
||||
abstract public bool Add(T t);
|
||||
|
||||
// Modifica objetos del almacen
|
||||
abstract public bool Mod(T t);
|
||||
|
||||
// Elimina objetos del almacen
|
||||
abstract public bool Del(T t);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user