enum RelationShip
{
Parent,
Child,
Silbing
}
class Person
{
public string Name;
public DateTime DateOfBirth;
}
interface ISearchRelationShip
{
IEnumerable<Person> SearchChild(string parentName);
}
class RelationShips: ISearchRelationShip
{
private List<(Person, RelationShip, Person)> ps = new List<(Person, RelationShip, Person)>();
public void AddRelationShip(Person parent, Person child)
{
ps.Add((parent, RelationShip.Parent, child));
ps.Add((child, RelationShip.Child, parent));
}
public IEnumerable<Person> SearchChild(string parentName)
{
foreach (var item in ps)
{
if (item.Item1.Name==parentName&&item.Item2==RelationShip.Parent)
{
yield return item.Item3;
}
}
}
}
internal class Program
{
public Program(ISearchRelationShip searchRelationShip)
{
Console.WriteLine("zhangsan has childs:");
foreach (var item in searchRelationShip.SearchChild("zhangsan"))
{
Console.WriteLine($" -{item.Name}");
}
}
static void Main(string[] args)
{
Person father = new Person() { Name="zhangsan"};
Person child1 = new Person() { Name = "zhangdada" };
Person child2 = new Person() { Name = "zhangxiaoxiao" };
RelationShips rs = new RelationShips();
rs.AddRelationShip(father, child1);
rs.AddRelationShip(father, child2);
new Program(rs);
}
}