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 aCharacter
. Similarly,Enemy
andAlly
inherit fromCharacter
Key
,Block
,Powerup
areObject
s
Association
Identify has a relationships:
- A
Game
has aWorld
- A
World
has multipleCharacter
s andObject
s
Realisation (Interface)
Identify can do relationships.
Player
, and someEnemy
s andAlly
s can attack and defend.- Some
Object
s can be picked up. - Some
Object
s can be used. - Some
Object
s can take damage and die - Some
Characters
andObjects
are interactable with thePlayer
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 aCollected()
method.Attack()
andDefend()
methods onCanAttackAndDefend
interface?Move()
method onCharacter
superclass- Define
Game
to have an instance attribute of typeWorld
- Define
World
to store multipleCharacter
s andObject
s etc.
4. Develop a Class Diagram
There are so many ways to do this:
But I’m lazy
Use Unified Modelling Language