Skip to content

Instantly share code, notes, and snippets.

@jsanjuan2016
jsanjuan2016 / A3F1.cs
Last active April 20, 2022 14:39
Artículo 3. Figura 1
public class Machine
{
public Machine()
{
}
private string Components { get; set; }
public List<string> GetComponents()
{
private readonly ICustomers _service;
public Client()
{
//Al estar accesibles de forma pública las implementaciones, un programador "despistado"
//podría saltarse el flujo de inversión de control y crear los objetos "a mano" mediante new
this._service = new Customers(new CustomerRepository());
}
services.AddTransient<IShapeFactory<Rectangle>, RectangleFactory>();
services.AddTransient<IShapeFactory<Circle>, CircleFactory>();
public class RectangleParameters : IShapeParameters
{
public double width { get; set; }
public double height { get; set; }
}
private readonly IShape _rectangle;
private readonly IShape _circle;
public WindowManager(IShape rectangle, IShape circle)
{
this._rectangle = rectangle ?? throw new ArgumentNullException(nameof(rectangle));
this._circle = cirlce ?? throw new ArgumentNullException(nameof(circle));
}
services.AddTransient<IShape, Rectangle>();
services.AddTransient<IShape, Circle>();
public interface IShapeParameters { }
public class WindowManager
{
private readonly IShapeFactory<Rectangle> _rectangleFactory;
private readonly IShapeFactory<Cirlce> _CircleFactory;
public WindowManager(IShapeFactory<Rectangle> rectangleFactory, IShapeFactory<Cirlce> CirlceFactory)
{
this._rectangleFactory = rectangleFactory ?? throw new ArgumentNullException(nameof(rectangleFactory));
this._CircleFactory = CirlceFactory ?? throw new ArgumentNullException(nameof(CirlceFactory));
}
public interface IShapeFactory<T> where T : IShape
{
IShape CreateShape();
}
private readonly IShape<Rectangle> _rectangle;
private readonly IShape<Circle> _circle;
public WindowManager(IShape<Rectangle> rectangle, IShape<Circle> circle)
{
this._rectangle = rectangle ?? throw new ArgumentNullException(nameof(rectangle));
this._circle = circle ?? throw new ArgumentNullException(nameof(circle));
}