I'm learning about polymorphism and I'm in the doubt whether what I'm doing is actually polymorphism or just inheritance?
If it is polymorphism what do you have in my code that I can clearly identify that 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();
}
}