- Each birthing room references its zoo's existing featured animal.
- Feeding through the birthing room changes the weight seen through FeaturedAnimal.
- Both access paths continue to identify the same mother after care is provided.
The class diagram shows the existing structure. The focused object diagram shows Como Zoo before its birthing room is connected to Dolly.
| Reference | Como Zoo | San Diego Zoo |
|---|---|---|
FeaturedAnimal |
Dolly, Weight 35.3 | Patti, Weight 3.27 |
BirthArea.Animal |
null | null |
FeaturedAnimal.Baby |
Unborn Animal, Weight 3.53 | Unborn Animal, Weight 0.327 |
Keep the existing names Sex, GetIsPregnant, and Animal.Baby. Keep both calls to MakePregnant() in the zoo-creation methods. The existing temperature setup remains unchanged: Como starts at 75.0 and San Diego at 77.0, each using its room's InitialTemperature to set Temperature.
The zoo and birthing room share the mother, but they do not yet have methods to coordinate her delivery.
Have the zoo call its birthing room, and have the room call its doctor. Clear the shared mother's Baby reference when the delivery step completes.
/// <summary>
/// Represents the doctor's delivery step.
/// </summary>
public void DeliverAnimal()
{
}/// <summary>
/// Updates the birthing room and mother when a pregnant animal gives birth.
/// </summary>
public void BirthAnimal()
{
Animal baby = null;
if (this.Mother != null)
{
if (this.Mother.GetIsPregnant())
{
this.Temperature += 0.5;
this.Doctor.DeliverAnimal();
this.Mother.Baby = null;
}
}
}/// <summary>
/// Starts the birth action in this zoo's birthing room.
/// </summary>
public void BirthAnimal()
{
this.BirthArea.BirthAnimal();
}The birth methods need a window action, and a second click must not feed a mother who has already given birth.
Add a button for each zoo. Check pregnancy before both the additional feeding and the birth call.
<Button x:Name="birthDingoButton" Content="Give birth to dingo" Click="birthDingoButton_Click"/>
<Button x:Name="birthPlatypusButton" Content="Give birth to platypus" Click="birthPlatypusButton_Click"/>
if (this.ComoZoo.FeaturedAnimal.GetIsPregnant())
{
this.ComoZoo.FeaturedAnimal.Eat(this.ComoZoo.FeaturedAnimal.Weight * 0.05);
this.ComoZoo.BirthAnimal();
}A null or empty message should not erase useful information already shown in the text box.
Use two separate early-return checks before the existing text assignment.