I am doing a builder and would like it to have the following behavior:
abstract class ClassePaiBuilder
{
public ClassePaiBuilder SetAtributo(string atributo)
{
// codigo
return this;
}
public string Build()
{
string result = "";
//processo os atributos e gero uma string
return result;
}
}
class ClasseFilhaBuilder : ClassePaiBuilder
{
public ClasseFilhaBuilder SetOutroAtributo(string outroAtributo)
{
// codigo
return this;
}
}
class Program
{
public void Run()
{
string valorQualquer = new ClasseFilhaBuilder()
.SetAtributo("atributo da classe pai")
.SetOutroAtributo("atributo da classe filha")
.Build();
}
}
Is it possible? In this case, the compilation is breaking down because in SetAtributo
I am returning the instance typed as ClassePaiBuilder
, which does not have the SetOutroAtributo
method.