I have two classes and they have fields of each other types. Now I want to inherit from these classes in parallel and some magic so that derived classes could have the same fields but in relative types to each other after inheritance.
class Leader {
public Follower slave;
}
class Follower {
public Leader master;
}
class Teacher : Leader {}
class Student : Follower {}
class Officer : Leader {}
class Soldier : Follower {}
Teacher.slave.GetType(); // Returns Student
Officer.slave.GetType(); // Returns Soldier
Student.master.GetType(); // Returns Teacher
Soldier.master.GetType(); // Returns Officer
Is there a pattern or any solution to get this implemented in C#?
Aucun commentaire:
Enregistrer un commentaire