public static void Main()
public void consumir(double cant)
public void CargarNafta(int cantidad)
this.cantidad = cantidad;
public double getCantidad()
public class PistonB:Piston
public PistonB(IMotor delegado):base(delegado)
public override void Arrancar()
for (int i = 0; i < 100; i++)
System.Console.WriteLine("Explosion Piston B");
motor.avisoExpolsionPiston(this.consumo, this.calor);
public class PistonA:Piston
public PistonA(IMotor delegado):base(delegado){}
public override void Arrancar()
for (int i = 0; i < 100; i++)
System.Console.WriteLine("Explosion Piston A");
motor.avisoExpolsionPiston(this.consumo, this.calor);
protected double consumo;
public Piston(IMotor delegado)
public virtual void Arrancar(){
for (int i = 0; i < 100; i++)
System.Console.WriteLine("Explosion Piston");
motor.avisoExpolsionPiston(this.consumo, this.calor);
public class Motor:IMotor
private double temperatura;
public Motor(IAuto delegado)
this.piston = new Piston[5];
this.piston[0] = new PistonA(this);
this.piston[1] = new PistonA(this);
this.piston[2] = new PistonA(this);
this.piston[3] = new PistonB(this);
this.piston[4] = new PistonB(this);
foreach (var p in this.piston)
public void avisoExpolsionPiston(double cant, double calor)
this.temperatura += calor;
System.Console.WriteLine("Temperatura: "+ this.temperatura + "°C");
this.auto.avisoExpolsionPiston(cant);
void avisoExpolsionPiston(double cant, double calor);
void avisoExpolsionPiston(double cant);
private TanqueNafta tanque;
this.motor = new Motor(this);
this.tanque = new TanqueNafta();
public void CargarNafta(int cantidad)
this.tanque.CargarNafta(cantidad);
public void avisoExpolsionPiston(double cant)
this.tanque.consumir(cant);
System.Console.WriteLine("Me quedan: " + this.tanque.getCantidad() + " litros");