...
The figures below illustrate some of the cases that must be handled, and which are tested by the our tests.
PlantUML Macro |
---|
object "hallvard: Person" as hallvard {
}
object "marit: Person" as marit {
}
object "jens: Person" as jens {
}
|
| marit.addChild(jens) hallvard.addChild(jens) | PlantUML Macro |
---|
object "hallvard: Person" as hallvard {
}
object "marit: Person" as marit {
}
object "jens: Person" as jens {
}
marit -> jens: children
jens -> marit: mother
hallvard -> jens: children
jens -> hallvard: father |
| Establish links with addChild. (Same effect as below) |
PlantUML Macro |
---|
object "hallvard: Person" as hallvard {
}
object "marit: Person" as marit {
}
object "jens: Person" as jens {
}
|
| jens.setMother(marit) jens.setFather(hallvard) | PlantUML Macro |
---|
object "hallvard: Person" as hallvard {
}
object "marit: Person" as marit {
}
object "jens: Person" as jens {
}
marit -> jens: children
jens -> marit: mother
hallvard -> jens: children
jens -> hallvard: father |
| Establish links with setMother og setFather. (Same effekt as above) |
PlantUML Macro |
---|
object "hallvard: Person" as hallvard {
}
object "marit: Person" as marit {
}
object "jens: Person" as jens {
}
marit -> jens: children
jens -> marit: mother
hallvard -> jens: children
jens -> hallvard: father |
| marit.removeChild(jens) hallvard.removeChild(jens)
| PlantUML Macro |
---|
object "hallvard: Person" as hallvard {
}
object "marit: Person" as marit {
}
object "jens: Person" as jens {
}
|
| Removal of links with removeChild. (Same effect as below) |
PlantUML Macro |
---|
object "hallvard: Person" as hallvard {
}
object "marit: Person" as marit {
}
object "jens: Person" as jens {
}
marit -> jens: children
jens -> marit: mother
hallvard -> jens: children
jens -> hallvard: father |
| jens.setMother(null) jens.setFather(null) | PlantUML Macro |
---|
object "hallvard: Person" as hallvard {
}
object "marit: Person" as marit {
}
object "jens: Person" as jens {
}
|
| Removal of links with setMother og setFather. (Same effekt as above) |
PlantUML Macro |
---|
object "hallvard: Person" as hallvard {
}
object "marit: Person" as marit {
}
object "jens: Person" as jens {
}
object "torkel: Person" as torkel {
}
object "jorunn: Person" as jorunn {
}
marit -> jens: children
jens -> marit: mother
hallvard -> jens: children
jens -> hallvard: father |
| jens.setFather(torkel) jens.setMother(jorunn) | PlantUML Macro |
---|
object "hallvard: Person" as hallvard {
}
object "marit: Person" as marit {
}
object "jens: Person" as jens {
}
object "torkel: Person" as torkel {
}
object "jorunn: Person" as jorunn {
}
jorunn -> jens: children
jens -> jorunn: mother
torkel -> jens: children
jens -> torkel: father |
| Remove and establish links with setMother og setFather, i.e. "adoption". |
The task is split in two parts, the first handles the children- and mother/father roles in isolation without considering consistency, while the other must ensure consistency.
The Exercise
...
panel
Use the Exercise - panel, open the Person.ex file (tests > objectstructures > Person.ex) in the panel before you start the start programming.
Part 1
- Implement the addChild and removeChild methods so the getChildCount and getChild methods work as expected. These methods only handle the children role.
- Implement the setMother and setFather methods so the getMother and getFather methods work as expected. These methods only handle the mother/father roles.
...
Extend the methods to handle consistency. Test by creating the same Person object structures as in part 1, this time by only using addChild and by only using setMother and setFather. Also run the JUnit tests for this programming task.
Test code for this task can be found here: objectstructures/PersonTest.java. The original jextest code can be found here: objectstructures/Person.jextest.
...