M
Matteo Migliore
Hi.
I've a problem with parent-child circular references.
Suppose have two classes, Person and Course:
--------------------------
public class Person{
public Person(string name, Course course){
this.name = name;
this.course = course;
}
string name;
public string Name { get{ return name;} }
Course course;
public Course Course { get{ return course;} }
}
public class Course{
public Course(string name, IList<Person> persons){
this.name = name;
this.persons = persons;
}
string name;
public string Name { get{ return name;} }
IList<Person> persons;
public Person Perons { get{ return persons;} }
}
--------------------------
How can I initialize a Person and a Course with their constructors?
Which class to create before?
Suppose that constructors check for not null.
Is this a correct solution (I intend for design, not for compile )?
I've a problem with parent-child circular references.
Suppose have two classes, Person and Course:
--------------------------
public class Person{
public Person(string name, Course course){
this.name = name;
this.course = course;
}
string name;
public string Name { get{ return name;} }
Course course;
public Course Course { get{ return course;} }
}
public class Course{
public Course(string name, IList<Person> persons){
this.name = name;
this.persons = persons;
}
string name;
public string Name { get{ return name;} }
IList<Person> persons;
public Person Perons { get{ return persons;} }
}
--------------------------
How can I initialize a Person and a Course with their constructors?
Which class to create before?
Suppose that constructors check for not null.
Is this a correct solution (I intend for design, not for compile )?