Function Structure Example

Consider the following implementation for a RangeCombiner class.

Group discussion

Look over the implementation in the handout, it should appear complicated.

  1. What do you think are the characteristics of this code that make it hard to understand?
  2. What could we do to make this class easier to understand? Work out some of the details of the change (are you introducing new methods, a new class, renaming things?).

Don’t read further until you have thoroughly discussed the two questions above.

In order to address the problems, we are going to have a small refactoring session, and we will use the incremental replacement method: Incrementally replace existing features with the new functionality. Recall the overall steps:

Here are the steps in detail (REMEMBER to CHECK your tests after each step):