Change the tire

Suppose you were given the Tire class to implement. In this class there is a method called changeTire()

Now, what exactly does that mean? How should you implement it?

Does changeTire() mean

  1. You have a flat tire while you are traveling.
    Here, changing the tire would mean that you are taking the tire off of the vehicle and putting on the spare.
  2. You had a nasty flat tire on the road and/or you are now at the tire store for replacements.
    Here, changing the tire means removing the tire from the rim and replacing it with a new tire.

The behaviour for these two situations are completely different, and the name of the method alone does not supply enough information. You, the implementor, need more information on which of these to implement, and you, the user, would like to be sure that the method you use is doing the action you are expecting and that you are calling the right one at the right time.

Writing PRE and POST conditions when designing the Tire class and the changeTire() method, will ensure that the programmer implements the correct behaviour.

Reading and considering PRE and POST conditions when using the Tire class and the changeTire() method, will ensure that the user calls the action expected and uses the right one at the right time.
For example, for the second example of changeTire(), a PRE condition may be something like the tire is off the rim and a new tire is available to put on the rim. A PRE condition for the first may be something like the tools available to remove the tire from the body are available, etc.

A designer, implementor, or user of a system should never expect a particular unstated interpretation of a method. PRE and POST conditions provide the contract under which agreements for the content are made.


The Mars Mission

Do you know why JPLs first Mars mission was not successful?

Someone did not pay attention to PRE and POST conditions.

JPL contracted out for a specific task that required measurements. The contractors did the job, but returned the value of the measurements in english units rather than metric. This simple error caused the failure in the mission!

If the PRE and POST were set and agreed upon, the product specs would have been clearly established and the taxpayers would not have paid millions/billions of dollars in vain.

P.S. My son Matthew was a TUL (tactical uplink lead) in the successful (2004/05) mission. I am so proud!

Dunes of Mars