@@ -9,7 +9,6 @@ public interface IPerson
99 {
1010 string Id { get ; }
1111 string Name { get ; set ; }
12- Gender Gender { get ; }
1312 void setFather ( IPerson father ) ;
1413 void setMother ( IPerson mother ) ;
1514 void addBrother ( IPerson brother ) ;
@@ -30,13 +29,17 @@ public class Person : IPerson
3029 public string Id => _id ;
3130
3231 private string _name ;
32+ private Gender _gender ;
3333 private IPerson ? _father ;
3434 private IPerson ? _mother ;
35- private Gender _gender ;
3635
3736 private HashSet < IPerson > _children = new HashSet < IPerson > ( ) ;
3837 private HashSet < IPerson > _brothers = new HashSet < IPerson > ( ) ;
3938 private HashSet < IPerson > _sisters = new HashSet < IPerson > ( ) ;
39+ private HashSet < IPerson > _daughters = new HashSet < IPerson > ( ) ;
40+ private HashSet < IPerson > _sons = new HashSet < IPerson > ( ) ;
41+
42+
4043
4144 public Person ( string name , Gender gender )
4245 {
@@ -50,12 +53,6 @@ public string Name
5053 set => _name = value ;
5154 }
5255
53- public Gender Gender
54- {
55- get => _gender ;
56- set => _gender = value ;
57- }
58-
5956 public void addBrother ( IPerson brother )
6057 {
6158 if ( ! this . getBrothers ( ) . Contains ( brother ) )
@@ -67,9 +64,16 @@ public void addBrother(IPerson brother)
6764
6865 public void addDaughter ( IPerson daughter )
6966 {
67+ if ( ! this . _daughters . Contains ( daughter ) )
68+ {
69+ this . _daughters . Add ( daughter ) ;
70+ }
71+
7072 if ( ! this . _children . Contains ( daughter ) )
7173 {
7274 this . _children . Add ( daughter ) ;
75+
76+
7377 }
7478 }
7579
@@ -84,6 +88,11 @@ public void addSister(IPerson sister)
8488
8589 public void addSon ( IPerson son )
8690 {
91+ if ( ! this . _sons . Contains ( son ) )
92+ {
93+ this . _sons . Add ( son ) ;
94+ }
95+
8796 if ( ! this . _children . Contains ( son ) )
8897 {
8998 this . _children . Add ( son ) ;
@@ -102,7 +111,7 @@ public IEnumerable<IPerson> getChildren()
102111
103112 public IEnumerable < IPerson > getDaughters ( )
104113 {
105- return _children . Where ( c => c . Gender == Gender . Female ) ;
114+ return _daughters ;
106115 }
107116
108117 public IPerson ? getFather ( )
@@ -122,7 +131,7 @@ public IEnumerable<IPerson> getSisters()
122131
123132 public IEnumerable < IPerson > getSons ( )
124133 {
125- return _children . Where ( c => c . Gender == Gender . Male ) ;
134+ return _sons ;
126135 }
127136
128137 public void setFather ( IPerson father )
0 commit comments