Skip to content

Instantly share code, notes, and snippets.

@JuanjoFuchs
Created June 8, 2012 15:15
Show Gist options
  • Save JuanjoFuchs/2896112 to your computer and use it in GitHub Desktop.
Save JuanjoFuchs/2896112 to your computer and use it in GitHub Desktop.
Ejemplo del principio de sustitución de Liskov (LSP)
namespace LSP_Animal.Refactorizado
{
public abstract class Animal
{
public abstract void Alimentar();
}
public interface IMascota
{
void Acariciar();
}
public class Perro : Animal, IMascota
{
public override void Alimentar()
{
// Alimentar al perro
}
public void Acariciar()
{
// Acariciar al perro
}
}
public class Escorpion : Animal
{
public override void Alimentar()
{
// Alimentar al escorpion
}
}
}
namespace LSP_Animal.SinRefactorizar
{
public abstract class Animal
{
public abstract void Alimentar();
public abstract void Acariciar();
}
public class Perro : Animal
{
public override void Alimentar()
{
// Alimentar al perro
}
public override void Acariciar()
{
// Acariciar al perro
}
}
public class Escorpion : Animal
{
public override void Alimentar()
{
// Alimentar al escorpion
}
public override void Acariciar()
{
// Estas loco ????!
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment