diff --git a/src/content/tutorials/en/getting-started-with-instance-mode.mdx b/src/content/tutorials/en/getting-started-with-instance-mode.mdx new file mode 100644 index 0000000000..65e4c3d2dc --- /dev/null +++ b/src/content/tutorials/en/getting-started-with-instance-mode.mdx @@ -0,0 +1,38 @@ +--- +title: Getting Started with p5.js Instance Mode +description: Learn how to set up and use p5.js in instance mode for better modularity and compatibility. +category: drawing +--- + +# Getting Started with Instance Mode + +## What is Instance Mode? + +Instance mode allows you to create multiple independent instances of the library, rather than relying on a single global instance. This approach provides better encapsulation, flexibility, and avoids conflicts in complex applications. + +## Why Use Instance Mode? + +Instance mode is preferred in scenarios where multiple independent configurations are needed within the same application. Unlike global mode, which shares state across all components, instance mode ensures better isolation and control. + +## Advantages of Instance Mode + +- **Encapsulation**: Each instance maintains its own state, avoiding unintended side effects. +- **Flexibility**: Different configurations can be applied to different instances. +- **Scalability**: Easier to manage in large applications with multiple independent modules. +- **Avoids Conflicts**: Prevents state pollution from shared global variables. +- **Better Testability**: Each instance can be tested independently. + +## Limitations of Instance Mode + +- **Increased Memory Usage**: Multiple instances consume more resources compared to a single global instance. +- **More Setup Required**: Requires explicit initialization for each instance. +- **Potential Redundancy**: If all instances share the same configuration, a global instance might be more efficient. + +## When to Choose Instance Mode Over Global Mode? + +- **When working with multiple independent modules** that require different configurations. +- **When developing modular applications**, ensuring isolated behavior. +- **When avoiding global state conflicts** is necessary. +- **When testing individual components**, making unit testing easier. + +By choosing instance mode in the right scenarios, you can achieve better modularity and maintainability in your project.