Object-Oriented Design

5 min. read

Object-Oriented Design

What are objects

Each has:
Identity (identify the object)
Attributes (width, height, full, empty, etc…)
Behaviours (things they can do, move, jump, etc…)

When to create an object?
Can you put the word “The” in-front of the object?
The mug
The person
The bank
Etc…

Classes describe what an object with be. Classes are the blueprints, like a house plan, it is not a house, but can be used to create a house.
The class comes first.

Classes has:
Name - the name of the class
Attributes - properties/members
Behaviours - methods/functions

Creating objects from classes is called instantiation

4 fundamental ideas in OOP (4 Pillars)

A - Abstraction
P - Polymorphism
I - Inheritance
E - Encapsulation

Abstraction
Have an idea but dont need an instance.

Encapsulation
Surrounding something
Information Hiding
Should only make information visible that other classes require
Black boxing
Make functions public, not attributes
Reducing dependencies between classes

Inheritance
Create a new class from an existing class
Eg: person class and then a customer class… same as person class, but has customerNumber. CustomClass Inherits from PersonClass
Parent class - SuperClass
Child class - Subclass
C++ can do multiple inheritance
Saves time

Polymorphism
Means “many forms”
Overrides the base methods

Analysis, Design and Development
Gather requirements
What does the app need to do?
What problems are we trying to solve?
Needs to be defined to clearly state: what the app could do versus what the app is going to do
Describe application
Describe how people will use the app
Use Cases and User Stories
Create mockup or prototype of the user interface, sometimes essential and other times it’s just a distractaction
Identify most important objects
Start of actual classes
Most important ideas, concepts, things and discard what’s irrelevant
Describe the interaction between those objects
Describe interaction between the classes, spaceship needs to explode when it hits a rocket.
The behaviours they have
When they interact with each other
What they do
And what order they do it in
Create a sequence diagram
Create Class diagram
Visual representation of the classes
This is not done once, but rather continually revisited

https://www.freecodecamp.org/news/four-pillars-of-object-oriented-programming/

Defining Requirements
Core requirements (functional requirements)
What are the features and capabilities of the app
What does it need to do

Non-functional requirements
Help - What help or documentation needs to be provided?
Legal - Are there legal requirements?
Performance - Performance requirements Responsiveness? Who many people does the app need to support at the same time?
Support - Support requirements
Security -

So not the hundred different things it might do or could do, but at leastinitially what the app must do. Now requirements can be phrased very simply. You’ll often see requirements begin with the phrase system must or application must or program must, depending on which term you prefer.

Core Requirements
App MUST ….
Game MUST….

Non-functional
Should be able to search matches
Provide support

FURPS+
F - Functional Requirements
U - Usability Requirements
R - Reliability requirements
P - Performance requirements
S - Supportability requirements
+
Design - Eg: must be an iphone app
Implementation - Language, Design Patterns, Methodology
Interface - 3rd Party systems
Physical - Eg: PC requirements

UML (Unified Modeling Language)

Use Cases
Title - What is the goal?
Actor - who desires it?
Scenario - how is it accomplished?

Best Title:
Should have a verb
Register new member
Transfer funds

Actor: Anything with behaviour and has a goal they want to achieve with the app
User
Customer
Member
Admin
ACMESystem
Any entity thats acts on our system
Scenario:
Write as steps
Normal expected flow?
No

Extensions: Problems

Preconditions: what must be true before this use case

How long? One or 2 days for requirements and use cases?
Dont use ‘use case diagrams’

User Stories

DRY - Dont Repeat yourself
YAGNI - You Ain’t goin need it
SOLID
Single Responsibility

GRASP
Expert/Information Expert
Creator
Low Coupling or High Cohesion

MVC - Model, View and Controller

MVC in Unity
Model - Data
View - 3D and GUI - Display data modules
Controller - Updates the data modules

Applying these principles to Unity.
Create Components.
Controllers
Data modules
App Controller