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
Playeris aCharacter. Similarly,EnemyandAllyinherit fromCharacter Key,Block,PowerupareObjects
Association
Identify has a relationships:
- A
Gamehas aWorld - A
Worldhas multipleCharacters andObjects
Realisation (Interface)
Identify can do relationships.
Player, and someEnemys andAllys can attack and defend.- Some
Objects can be picked up. - Some
Objects can be used. - Some
Objects can take damage and die - Some
CharactersandObjectsare 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):
Collectibleinterface, which implements aCollected()method.Attack()andDefend()methods onCanAttackAndDefendinterface?Move()method onCharactersuperclass- Define
Gameto have an instance attribute of typeWorld - Define
Worldto store multipleCharacters andObjects etc.
4. Develop a Class Diagram
There are so many ways to do this:
But I’m lazy
Use Unified Modelling Language
