Last updated: May 01, 24 18:34 UTC | Permalink

Overview

In this activity, you will do a simple example to help you recognize failure of the five code-level design principles

Step 0: Getting started

Start by downloading the (Starter Code). Run npm install to download the dependencies for this project, and then open it in your IDE of choice. Run npm run test to run the tests of the existing code (or run the script in VSC). You will see that the tests pass.

The Problem

Your team is writing a simulator for a traffic light in a large city. Whitley, an intern in your group, has written the code in TrafficLight.ts, and the tests in TrafficLight.test.ts

Your team leader, Adrian, has asked you to critique Whitley’s code based on the Five Code-Level Design Principles. Adrian says that he has already received some feedback from the client, who complained that not all traffic lights change when they are expected (they expect all lights to change at the same time, and for the red to be 20, yellow 5 and green 15 seconds). Moreover, the lights in different intersections are not synchronized, so that cars have to stop at every intersection.

Part 1: Critique Whitley’s code.

In a text file, list several ways in which Whitley’s code violates the 5 Principles.

Part 2: Improve Whitley’s code

Write a new file, called betterTrafficLight.ts, which Principles, and addresses some of the problems raised by the customer. Test your code by changing TrafficLight.test.ts to import from betterTrafficLight.ts

Part 3: Critique your own code

Now look at your own code. Based on your experience with traffic lights, list 3 assumptions that your code makes about the behavior of traffic lights in a large city. In what ways is the client likely to be unhappy with the assumptions you made? (Stretch goal: how could you redesign your code to make it more flexible?)

Submit your work

Instructions for submitting this activity will appear in Canvas.


© 2024 Jon Bell, Adeel Bhutta and Mitch Wand. Released under the CC BY-SA license