Factory

What is it?

A Factory is a design pattern from object-oriented programming that centralizes and abstracts object creation. In both 3D and web development you use a factory to create different concrete object types (e.g., meshes, materials, UI components, or API clients) in a uniform way without the caller knowing construction details. This makes code more maintainable, testable and flexible: you can swap implementations, integrate resource management and pooling (important for real-time 3D), and apply configuration or lazy loading more easily. A factory can be a simple function that returns objects or a fuller Abstract Factory / Factory Method implementation in larger systems.

Practical example

Imagine a web app with an embedded 3D viewer (e.g., Three.js) and a set of associated UI widgets. A factory can, for a given 'vehicle' type, create a predefined mesh, material and physics parameters and at the same time configure and return the corresponding HTML/React components (buttons, sliders). In another case a factory performs object pooling for frequent 3D particles to reduce allocation cost, while the same factory in the web layer produces standardized DOM elements or fetch clients with preset headers and error handling. By keeping creation in a single place you can easily swap variants (low-poly vs high-poly, mock API vs real API) without changing the rest of the application.

Test your knowledge

What is the primary advantage of applying the Factory pattern in an application that manages both 3D elements (e.g., meshes, materials) and web components (UI, API clients)?

Ask Lex
Lex knows the context of this term and can give targeted explanations, examples, and extra context.
Tip: Lex replies briefly in the widget. For more detail, go to full screen mode.

Learn our language

Learn these terms from real professionals and take your skills further at KdG MCT.

Study at KdG