Answer the question
In order to leave comments, you need to log in
Generic inheritance, how to do it right?
I tried to make a fairly simple example: two classes Foo and Boo "depend" on each other.
public class Foo<T, U> where T : Boo<U, T> where U : Foo<T, U>
{
protected readonly T _some;
public Foo(T some)
{
_some = some;
}
}
public class Boo<T, U> where T : Foo<U, T> where U : Boo<T, U>
{
protected readonly T _some;
public Boo(T some)
{
_some = some;
}
}
public class Too : Foo<Roo, Too>
{
public Too(Roo a) : base(a)
{
}
}
public class Roo : Boo<Too, Roo>
{
public Roo(Too b) : base(b)
{
}
}
public class Roo : Boo< Too, Roo >
Answer the question
In order to leave comments, you need to log in
It’s even difficult to read, you get confused who depends on whom.
I've never seen anything like this, especially in production, and I hope I won't :)
There is a free report on generics from Jeffrey Rechter - https://youtu.be/H9mP0Ad3TtA?t=4666
Day 1, Hall 1, report 1.
He will tell you how they appeared and why.
In general, the generic is useful for defining templates and avoiding "packaging".
Is there a syntactic option to not specify itself in the parent public class Roo : Boo< Too, Roo >
?
I got to this game myself, studying generic types. To what extent is this design generally acceptable and viable? What are the practices?
public class List : BaseAsyncEndpoint
.WithRequest<AuthorListRequest>
.WithResponse<IList<AuthorListResult>>
{
// ...
}
In general, a generic is useful for defining templates and avoiding "packaging".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question