Implementation

Let's take a bottom-up approach. An assert requires us to have a planet getter:

private Planet planet;
public Planet getPlanet() {
  return planet;
}

Next, the constructor should accept Planet as a second argument and assign it to the previously added planet variable. The first attempt might be to add it to the existing constructor, but that would break many existing specifications that are using a single argument constructor. This leaves us with only one option—a second constructor:

public Ship(Location location) {
  this.location = location;
}
public Ship(Location location, Planet planet) {
  this.location = location;
  this.planet = planet;
}

Run all the specifications and confirm that they are all successful.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.177.86