10 — Refactoring

Due Sunday, 27 March, midnight

Your software architect has decided that it is time to curate your code and test suites.

Task 1 Inspect your code and test suites. Make sure that at the end of the week you have accomplished the following:

  1. Use natural signatures of major methods, not the one that the external test harness suggests. For example, when the test harness demands a "functional" feeding step from your a dealer, as in,

        Configuration -> Configuration

    your dealer class should still use an imperative signature because it modifies its own state:

        -> Void

    The key is that the test harness creates the dealer from the JSON and then extracts JSON after the dealer has run the feeding step.

    For imperative methods, formulate an effect statement; for functional ones, formulate a purpose statement.

  2. Shorten every method so that it is at most 20 lines long. For this goal keep in mind that, for example, a dealer does not feed a species directly. It asks the player-owner to feed the species, which in turn just tells the species to eat a food token.This idea of delegating to owned objects is often called Law of Demeter, and this name was coined by your very own Herr Prof. Dr. Lieberherr.

  3. Look for repeated patterns and abstract them into a method.

  4. Ensure that tests for imperative methods not only check that the desired change takes place but also check that things that should not change remain the same. And if you don’t have unit tests for your major methods, now is the last chance you have to create them. (Of course, you must realize that you have been under time pressure because you did not formulate tests up front.)

  5. Your software passes many more tests from the test fest than last week.

Note We will re-run the test fest tomorrow to address questions that some of you asked.