There are five main steps involved in the design process of creating software from a design spec, using OOP.

Here is the example problem spec:

This game involves a number of characters, like the player, their allies, and their enemies. Some of these characters walk around the world, and some allow the player to interact with them. There are also other objects in the game like keys, blocks, and power-ups, some of which can be interacted with, some that can be collected/picked up, and some that can be “used” after being picked up. Some objects in the game have health and can “die”, while some are killed or removed instantly. Other objects can attack and defend other characters.

1. Identify Classes

This can be boiled down to extracting the key nouns from the specsheet, however, there may be some more classes than just the nouns.

For example:

This game involves a number of characters, like the player, their allies, and their enemies. Some of these characters walk around the world, and some allow the player to interact with them. There are also other objects in the game like keys, blocks, and power-ups, some of which can be interacted with, some that can be collected/picked up, and some that can be “used” after being picked up. Some objects in the game have health and can “die”, while some are killed or removed instantly. Other objects can attack and defend other characters.

From this we have some key classes:

  • Game, World, etc.
  • Character, Player, Ally, Enemy, etc.
  • Objects, Keys, Blocks, Powerups, etc.

2. Identify Class Relationships

This step involves identifying the various Class Relationships that exist between classes.

Generalisation (Inheritance)

Identify is a relationships:

  • A Player is a Character. Similarly, Enemy and Ally inherit from Character
  • Key, Block, Powerup are Objects
Association

Identify has a relationships:

  • A Game has a World
  • A World has multiple Characters and Objects
Realisation (Interface)

Identify can do relationships.

  • Player, and some Enemys and Allys can attack and defend.
  • Some Objects can be picked up.
  • Some Objects can be used.
  • Some Objects can take damage and die
  • Some Characters and Objects are interactable with the Player
Dependency

Identify needs a relationships, that are not already covered under association:

  • None?

3. Refine Classes & Relationships

This is usually when you start defining Method signatures, and Attributes. You can also start creating your Abstract Methods, Abstract Class and Interfaces.

A few examples (because there are a lot in the specsheet):

  • Collectible interface, which implements a Collected() method.
  • Attack() and Defend() methods on CanAttackAndDefend interface?
  • Move() method on Character superclass
  • Define Game to have an instance attribute of type World
  • Define World to store multiple Characters and Objects etc.

4. Develop a Class Diagram

There are so many ways to do this:

But I’m lazy

Use Unified Modelling Language

Pasted image 20240909164717