# clpsplug/pooledobjects architecture

> Architecture diagram of the GitHub repository clpsplug/pooledobjects, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/clpsplug/pooledobjects
- Repository: https://github.com/clpsplug/pooledobjects

## Overview

##### Main Components
- Runtime Library:
- PooledObjects Class: The core generic class that manages the pool. (Runtime/PooledObjects.cs)
- Related Utilities: For instance, Exceptions handling (Runtime/Exceptions.cs) and any pool info gathering (Runtime/PoolInfoGatherer.cs).
- Interface: The project assumes the existence of an IPoolable interface (though not shown separately, it is central to indicating if an object is “in-use” or not).
- Editor Extension:
- PoolInspector: Code in Editor/PoolInspector.cs shows there is a custom inspector tool for pooled objects in the Unity Editor.
- Configuration/Package Metadata:
- The package file (package.json) indicates the integration with the Unity Package Manager (UPM).
- .asmdef files in both Editor and Runtime directories signify assembly boundaries within Unity.

##### Relationships and Interactions
- The Runtime part is responsible for creating and managing pools:
- When a pool is initialized, it instantiates multiple GameObject instances from a prefab and stores them as inactive.
- The Spawn() and Despawn() methods control the lifecycle—activating and deactivating GameObjects.
- ExhaustionBehaviour settings influence the pool’s behavior when no available instances remain.
- The user scripts (for example, a custom MonoBehaviour implementing IPoolable) integrate with and extend this system to handle application-specific behavior.
- The Editor extension (PoolInspector) likely provides a streamlined interface to view and diagnose the status of the pool within the Unity Editor.

##### Architectural Patterns and Principles
- Separation of Concerns: Notice how the runtime logic (pooling and object lifecycle) is separated from the editor functionalities (pool inspection and debugging).
- Reusability & Extensibility: The use of a generic base class (PooledObjects<T>) and an IPoolable interface demonstrates a design that allows pooling for different types of objects (not necessarily limited to MonoBehaviours).
- Loose Coupling: The pool is designed so that the calling code simply instantiates, uses, and eventually despawns objects without worrying about underlying instantiation overheads.
- Configuration Flexibility: The use of an enumeration (ExhaustionBehaviour) to handle what happens if the pool is exhausted shows an emphasis on configurable behavior.

##### Final Detailing
- That each component, such as “Exceptions Handling” and “Pool Info Gathering”, is linked to the “Pool Manager” to show how they support runtime error handling and performance diagnostics.

– The instantiation and management of pooled objects via the core runtime mechanisms.
– The integration of user scripts and how custom pool classes derive from the base pooling mechanism.
– The monitoring/inspection capabilities provided by the Editor tools.
This approach will ensure that every crucial architectural element is represented in a comprehensive, yet clear, overview tailored to this Unity pooling library project.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Configuration and Assembly"
        Package["Package Configuration (UPM)"]:::config
        AR["Runtime Assembly Definition"]:::config
        AE["Editor Assembly Definition"]:::config
        Package -->|"defines"| AR
        Package -->|"defines"| AE
    end

    subgraph "Runtime Module"
        PO["PooledObjects (Runtime Core)"]:::runtime
        E["Exceptions Handling"]:::runtime
        PI["Pool Info Gathering"]:::runtime
        IP["IPoolable Interface"]:::runtime
        Pref["Prefab Instances"]:::runtimeNote
        Exhaust["ExhaustionBehaviour Configurations"]:::runtimeNote
        PO -->|"Initialize/Spawn/Despawn"| Pref
        PO -->|"Handles"| E
        PO -->|"Monitors"| PI
        PO -.->|"Depends on"| IP
        PO ---|"Configured With"| Exhaust
    end

    subgraph "Editor Module"
        PI2["PoolInspector (Editor Extension)"]:::editor
    end

    subgraph "User Layer"
        User["User Implementation (PooledMonoBehaviour)"]:::user
    end

    User -->|"Uses"| PO
    PI2 -->|"Inspects"| PO

    click PO "https://github.com/clpsplug/pooledobjects/blob/base/Runtime/PooledObjects.cs"
    click E "https://github.com/clpsplug/pooledobjects/blob/base/Runtime/Exceptions.cs"
    click PI "https://github.com/clpsplug/pooledobjects/blob/base/Runtime/PoolInfoGatherer.cs"
    click PI2 "https://github.com/clpsplug/pooledobjects/blob/base/Editor/PoolInspector.cs"
    click AR "https://github.com/clpsplug/pooledobjects/blob/base/Runtime/clpsplug.PooledObjects.Runtime.asmdef"
    click AE "https://github.com/clpsplug/pooledobjects/blob/base/Editor/clpsplug.PooledObjects.Editor.asmdef"
    click Package "https://github.com/clpsplug/pooledobjects/blob/base/package.json"

    classDef runtime fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef editor fill:#A9DFBF,stroke:#239B56,stroke-width:2px;
    classDef config fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef user fill:#F5B7B1,stroke:#B03A2E,stroke-width:2px;
    classDef runtimeNote fill:#FDEBD0,stroke:#D35400,stroke-width:2px,stroke-dasharray: 5 5;
```
