Table of Contents

Namespace WitShells.DesignPatterns.Core

Classes

AddStrategy

Example strategy that adds two integers together.

Bindable<T>

A reactive property wrapper that automatically fires a UnityEvent<T> whenever its value changes. Use this to implement the Observer / Data-Binding pattern without manual event wiring.

Builder<T>

Abstract base class for the Builder pattern. Extend this class and add fluent setter methods to construct complex objects step-by-step, keeping construction logic separate from the product class itself.

CommandInvoker

The Invoker in the Command pattern. Executes ICommand instances and maintains a history stack that allows undoing operations in LIFO order.

Component

Base class for all ECS Components. A component is pure data with no behaviour — it describes one aspect of an Entity (e.g. position, health, inventory). Derive from this class to create custom components.

DraggableItem<T>

Abstract MonoBehaviour base class for draggable UI items in the Drag-and-Drop system. Handles pointer events, canvas hierarchy management (render-on-top), transparency during drag, and optional snap-back to the original position.

DropZone<T>

Abstract MonoBehaviour base class for Drop Zone areas in a drag-and-drop system. Responds to Unity pointer events (IDropHandler, IPointerEnterHandler, IPointerExitHandler) and delegates acceptance logic to concrete subclasses. Provides visual highlight feedback when a compatible draggable hovers over the zone.

Entity

Represents a game object in the Entity-Component-System (ECS) pattern. An entity is nothing more than a container of Component instances — it has no logic itself. Behaviour is provided by systems that query entities for required components.

FlyweightFactory<TKey, TFlyweight>

Generic Flyweight Factory that caches and reuses flyweight instances keyed by TKey. If a flyweight for a given key already exists it is returned directly, otherwise it is created via the supplied factory delegate and cached.

FormationUtils

Static utility class that generates world-space Pose lists for common tactical/game unit formations. Each method returns a list of positions and rotations that can be assigned to agents, NPCs, or any Unity objects.

GenericFactory<TKey, TProduct>

A generic, key-based Factory that creates new product instances on demand. Creator delegates are registered once and called every time a new object is needed, so each call to Create(TKey) returns a fresh instance.

GenericSingleFactory<TKey, TProduct>

Abstract Singleton-per-key Factory that creates at most one instance of TProduct per TKey. On the first call to Get(TKey) for a given key the creator is invoked and the result is cached. Subsequent calls return the cached instance.

HealthComponent

Example ECS component that stores an entity's health points.

HealthSystem

Example ECS system that operates on entities possessing a HealthComponent. Systems hold the game logic and iterate over relevant entities each update tick.

IdleState

Example IState — represents an entity standing still. Replace the placeholder comments with your own idle behaviour.

LocalFileSystem

A static async helper for persisting data to the local file system with AES-256 encryption and GZip compression.

LocalFileSystemException

Exception thrown by LocalFileSystem when a file operation fails (e.g. wrong password, missing file, or corrupt data).

Mediator

A concrete, event-bus style Mediator implementation. Components subscribe to named event channels and are notified whenever another component calls Notify(object, string, object).

MonoSingleton<T>

Thread-safe MonoBehaviour Singleton base class. Subclass this to create a manager or service that must have exactly one instance in the scene. The instance is auto-located via FindFirstObjectByType and optionally kept alive across scene loads via DontDestroyOnLoad.

MoveState

Example IState — represents an entity in motion. Replace the placeholder comments with your own movement behaviour.

MovementComponent

Example ECS component that stores an entity's movement speed.

MultiplyStrategy

Example strategy that multiplies two integers together.

NodeController<T>

Abstract reactive node wrapper that combines the Builder, Observer, and Bindable patterns into a single unit. Each node wraps a value of type T inside a Bindable<T> so that listeners are automatically notified on change. When the node is no longer needed, call Dispose() to broadcast its removal via OnRemoved.

NodesManager<T>

A simple list-backed INodeManager<T> that stores nodes in insertion order. Duplicate nodes (by reference) are rejected.

ObjectPool<T>

A generic Object Pool that recycles instances of T to reduce heap allocations and GC pressure. Objects are retrieved with Get() and returned with Release(T) after use.

ObserverPattern<T>

A lightweight, generic implementation of the Observer pattern. Maintains a list of subscriber callbacks and notifies them all when a value is published. Prefer this over C# events when you need runtime subscribe/unsubscribe with no delegate leak risk, or when you want to store the observer list as a field rather than as a static event.

Player

Example product class used to demonstrate the Builder pattern. Represents a game player with a name, health, and movement speed.

PlayerBuilder

Concrete builder that constructs a Player using a fluent API. Call the Set* methods in any order, then call Build() to get the result.

PrintCommand

Example ICommand implementation that prints a message to the console. Undo() logs an acknowledgement that the print was undone.

SceneObjectCache

A lightweight, non-singleton cache for scene objects.

  • Finds the first object of type T in the scene using Unity's FindFirstObjectByType.
  • Caches the found instance per-type to avoid repeated scene searches.
  • If the cached object gets destroyed or is missing, the cache re-finds it on the next access.

Use this when multiple systems need access to a shared scene object without forcing a Singleton pattern.

ServiceLocator

A global, type-keyed Service Locator that acts as a lightweight alternative to dependency injection. Systems register their implementations once and any other system can retrieve them by interface/type without knowing the concrete class.

StateMachine

A simple, non-MonoBehaviour State Machine that drives an IState. Call ChangeState(IState) to transition and Update() each frame to tick the active state.

StrategyContext<TContext, TResult>

The Context class in the Strategy pattern. Holds a reference to the current strategy and delegates execution to it. The active strategy can be swapped at runtime via SetStrategy(IStrategy<TContext, TResult>).

TemplateMethod<TInput, TResult>

Abstract base class for the Template Method pattern. Defines the skeleton of an algorithm in Execute(TInput) (the template method) while delegating the concrete steps to subclasses via abstract methods. This lets subclasses change specific parts of the algorithm without altering its overall structure.

TreeFlyweight

Example IFlyweight that stores shared tree mesh and texture data. Many tree instances in the scene can reference a single TreeFlyweight; each instance provides its own position via the extrinsic state argument.

UniqueNodesManager<T, TKey>

A dictionary-backed INodeManager<T> that groups nodes by a computed key of type TKey. Multiple nodes may share the same key.

UserInputTemplate

Example template that parses a raw string into an integer, with logging at each step.

Interfaces

IBuilder<T>

Defines the contract for the Builder pattern. Implementors construct a product of type T step-by-step and return it via Build().

ICommand

Defines the contract for the Command pattern. Each command encapsulates a single action and its reversal, enabling undo/redo stacks, macro recording, and deferred execution.

IDraggable<T>

Contract for a draggable UI item that carries data of type T. Implement this interface (via DraggableItem<T>) to participate in drag-and-drop interactions with DropZone<T>.

IFlyweight

Defines the contract for a Flyweight object. The flyweight stores only intrinsic (shared, immutable) state; extrinsic (per-instance) state is passed in via Operation(object).

IMediator

Defines the contract for the Mediator pattern. The mediator decouples components (colleagues) by acting as a central hub for communication — instead of referencing each other directly, components send messages through the mediator.

INodeManager<T>

Defines the contract for a collection manager that stores and queries NodeController<T> instances.

IPrototype<T>

Defines the contract for the Prototype pattern. Classes implementing this interface are responsible for producing a deep copy of themselves, allowing the creation of new objects by cloning an existing configured instance rather than constructing one from scratch.

IState

Defines the contract for a single state in the State Machine pattern. Each state owns its own entry, update, and exit logic, keeping behaviour self-contained and easy to extend.

IStrategy<TContext, TResult>

Defines the contract for the Strategy pattern. Each strategy encapsulates one interchangeable algorithm that transforms a TContext value into a TResult value.