This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 7: More classes for your robot!

Identifying new classes

face Josiah Wang

You have previously refactored your robot project to use a RobotFactory class (or equivalent) to create new Robots each with a name, id, initial position and direction.

I am not sure about your code, but my main.py is much shorter now. It now contains only the “main” program that simulates robot navigation, along with two functions to generate the target cells (for the Ribena drink). I also have a function to read in candidate robot filenames from a file which technically can be moved to RobotFactory if preferred. I decided to keep this in main.py.

Now, we can go on refactoring like how we did (TargetCellGenerator class?), but perhaps we can use this chance to try to redesign our program to be even more object-oriented.

Here is my current class diagram (yours might look different). RobotFactory has a dependency on Robot since its job is to create new robots.

Class diagram for Robot project

Now, take a moment to recall the details of your robot program. Visualise the program in your mind (imagine robots navigating on the grid). Can you think of any other objects or entities that have not yet been modelled?

If it helps, try to identify any NOUNS that are involved in your program. They can even be abstract nouns (e.g. RobotFactory).

Spend one or two minutes thinking about this, then move on!