10
I’m learning about polymorphism and I’ve been wondering if what I’m doing is actually polymorphism or just inheritance?
If it’s polymorphism what’s in my code that I can clearly identify is polymorphism?
If it is not, what could be done to be polymorphism?
public abstract class Pessoa
{
public abstract int Id { get; set; }
public abstract string Nome { get; set; }
public abstract void Andar();
}
public class Comprador : Pessoa
{
public override int Id { get; set; }
public override string Nome { get; set; }
public override void Andar()
{
throw new NotImplementedException();
}
public void Comprar()
{
}
}
public class Vendedor : Pessoa
{
public override int Id { get; set; }
public override string Nome { get; set; }
public override void Andar()
{
throw new NotImplementedException();
}
public void Vender()
{
}
}
public class Sistema
{
public void MeuMetodoTeste()
{
Comprador pessoaComprador = new Comprador();
pessoaComprador.Comprar();
Vendedor pessoaVendedor = new Vendedor();
pessoaVendedor.vender();
}
}
Related to Heritage and Polymorphism
– Taisbevalle
https://msdn.microsoft.com/pt-br/library/ms173152.aspx
– Pablo Tondolo de Vargas