Object Orientation in C# - Inheritance

Asked

Viewed 202 times

-3

In relation to Orientação Objeto in the C#, have the following doubt:

What is the difference between the inheritance of code reuse, of builders, of abstract methods, of superclasses and of subclasses?

It does not refer to duplicate, because I do not want the definition of Inheritance in object oriented. The question is different. Examples would be helpful.

  • 1

    @Uzumakiartanis does not refer to the duplicate, my question is different. In the suggested solutions does not even mention the reuse of builders, of superclasses, and of subclasses.

1 answer

2


The meanings of each concept have already been perfectly explained in this question: Meaning of terminology: "Object oriented"

But as you asked for some examples of how to implement, it follows a very simple code with some of the concepts cited above

#region Classe Abstrata
public abstract class Classe
{
    #region Método Abstrato
    public abstract void tratarValor(double valor);
    #endregion
}
#endregion

#region Classe
public class ClassePai
{       
    #region Construtor
    public ClasseFilha()
    {
        Console.Write("Classe Pai Cconstruida");
    }
    #endregion

    #region Sobrecarga de método
    public void imprimirCumprimento()
    {
        Console.Write("Olá!");
    }

    public void imprimirCumprimento(String nome)
    {
        Console.Write("Olá " + nome);
    }
    #endregion  

    public void imprimirIdentificacao()
    {
        Console.Write("Eu sou a classe Pai");
    }   
}
#endregion 

#region SubClasse
public class ClasseFilha
{   
    #region Construtor          
    private int variavelQualquer;

    public ClasseFilha(int variavelQualquer)
    {
        this.variavelQualquer = variavelQualquer;
    }
    #endregion

    #region Encapsultamento
    private String nomePai;

    public void setNomePai(String nomePai)
    {
        this.nomePai = nomePai;
    }

    public String getNomePai()
    {
        return this.nomePai;
    }
    #endregion

    #region Associação de Classes
    ClasseAssociacao classeAssociada = new ClasseAssociacao();
    #endregion

    #region Sobrescrita de método
    public override void imprimirIdentificacao()
    {
        Console.Write("Eu sou a classe Filha");
    }
    #endregion
}
#endregion

public class ClasseAssociacao
{
    String assosiacao = "Nada";
}

As I remember a few more concepts I will implement in the example

Browser other questions tagged

You are not signed in. Login or sign up in order to post.