Skip to main content

Class Naming

Written by: Akram Taghavi-Burris | © Copyright 2024
Status

  • Written in PascalCase (capitalizing the first letter of each word).
  • Generally written as a nouns that represent objects or entities.
    • Example: Player, NPC, Weapon
  • For classes that define specific behaviors or actions, write as a verb
    • Example: MoveLeftRight, JumpHandler

Creational Patterns

These patterns are designed to deal with the creation of objects, how and where an object is made.

CategoryTypePrefixSuffixExample NameNotes
ScriptFactory-FactoryEnemyFactoryResponsible for creating instance of a general type of object based on logic, without specifying exact details of each object.
ScriptObject Pool-PoolEnemyPoolManages a pool of reusable objects to optimize performance and resource usage.
ScriptPrototype-PrototypeEnemyPrototypeCreates new objects by copying existing ones, useful for generating similar objects efficiently.
ScriptSpawner-SpawnerEnemySpawnerManages the creation and placement of objects, often used to control dynamic object generation in games.
ScriptSingletonS-SDatabaseConnectionImplements the Singleton design pattern, ensuring only one instance of the class exists.

Structural Patterns

These patterns are built to show the relationships between entities.

CategoryTypePrefixSuffixExample NameNotes
ScriptComponent-ComponentHealthComponentRepresents a part or module that can be attached to game objects.
ScriptDecorator-DecoratorPlayerDecoratorEnhances or adds functionality to existing classes or components.
ScriptFlyweight-FlyweightBulletFlyweightReduces memory usage by sharing common data among similar objects, useful for managing large numbers of similar objects efficiently.
ScriptService-ServiceAudioServiceProvides specific services or utilities, often to decouple functionality.
ScriptUI ElementUI- UIInventory, UIStartButtonUsed for classes that manage UI elements.

Behavioral Patterns

These patterns are designed to deal with how objects communicate with each other.

CategoryTypePrefixSuffixExample NameNotes
ScriptGeneral--Tree, Lamp, BoxBasic MonoBehaviour classes used for simple, one-off game objects. These typically have no specific prefix or suffix.
ScriptAbstract Class-BaseCharacterBaseUsed for abstract or foundational classes that are not instantiated directly but serve as base classes for inheritance.
ScriptBehaviour-BehaviourAIBehaviourDefines specific behaviors or actions in the context of game objects.
ScriptCommand-CommandMoveCommandEncapsulates actions as objects, making it easy to manage, undo, or repeat them. Useful for things like undo functionality and command history.
ScriptController-ControllerPlayerControllerManages input and interaction logic for game objects.
ScriptEvent-EventGameEventRepresents events that can be triggered and handled in an event-driven system.
ScriptInterfaceI-IDamageableDefines a contract for classes; the I prefix is sometimes used to denote interfaces.
ScriptManager-ManagerGameManagerManages game-wide logic or specific aspects of the game, like audio or input. They are often singletons but not always.
ScriptObserver-ObserverScoreObserverNotifies subscribed objects when a change occurs. Useful for event-driven systems where multiple components need to react to changes.
ScriptScriptableObject-DataPlayerDataUsed to create assets that hold data; the Data suffix indicates that the object is used for storing data.
ScriptState-StatePlayerStateRepresents a particular state or condition within a state machine.
ScriptStrategy-StrategyMovementStrategy or IMovementStrategyRepresents a strategy or algorithm used by a class or component. Strategy classes are typically Interfaces.
ScriptSystem-SystemCombatSystemRepresents large-scale systems that manage complex logic or workflows.
ScriptUtility/Helper-Utility, HelperMathUtility, StringHelperProvides utility functions or methods, often static and used across various parts of the code.

Inclusive Word Choice:

The following provides guidance and suggestions to help you choose words and names that are respectful and appropriate for all situations and audiences and be a more effective communicator.

Word NameAlternative Word Name
Blacklistdeny list, block list, exclude list, avoid list, unapproved list, forbidden list, permission list
Whitelistallow list, include list, trust list, safe list, prefer list, approved list, permission list
Masterprimary, source, controller, template, reference, main, leader, original, base
Slavesecondary, replica, agent, follower, worker, cluster node, locked, linked, synchronized