Is it possible to somehow have this scenario where AN inherits the code from A using this code example?
The reason for this setup is that I need several classes that inherit from Base<TType>and Nested : Base<TType>, where the server has only the base, and the client has the extended Nested. Thus, it would be easy to use code where they would have common code between themselves and with each other.
The problem is that I would have to write identical code inside
A and A.N
B and B.N
C and C.N
etc..
I solved this temporarily by replacing the nested abstract class with an interface and doing it
A.N : A, INested, but now I have to rewrite the code Base<TType>.Nestedagain in all Nested classes. Currently, the nested class is small and manageable.
hope this is not a confusing question ...
public abstract class Base<TType> where TType : class
{
public TType data;
internal void CommonCodeForAll() { }
public abstract void Update();
public abstract class Nested : Base<TType>
{
public abstract void Input();
}
}
public class A : Base<someClass>
{
public float Somevariable;
public void SpecificFunctionToA() { }
public override void Update()
{
}
public class N : A.Nested
{
public override void Input()
{
if (data.IsReady()) { Somevariable *= 2; }
SpecificFunctionToA();
}
}
}
public class B : Base<anotherClass>
{
public float Somevariable;
public int index;
public int[] Grid;
public void SomethingElse() { }
public override void Update()
{
}
public class N : B.Nested
{
public override void Input()
{
if (Grid[index] == -1) { SomethingElse(); }
data.Somevariable = Grid[index];
}
}
}
Edit:
, , .
, , .
, , .