See all glossary termsA design pattern is a formalized solution to a software structure, performance, or design problem. Design patterns are sometimes regarded as good practices, but you can instead see them as literal patterns that you keep as part of your programmer toolbox to work around the limitations of the programming language you use and solve common problems.
Design patterns are not specific code snippets. Instead, they are concepts that you can implement in different ways depending on the programming language and framework you use. There are dozens of established patterns like this, including State, also known as "finite state machines", Singletons, type object, and many more. Different patterns have a different purpose.
Some are designed to help with performance, while others help make the code flexible or compartmentalized. Some are abstractions that help you think about the code differently, while others are more concrete solutions to common problems.
Godot comes with several patterns pre-implemented for your convenience. For example, signals are Godot's version of the observer pattern: they allow you to connect different parts of your code without objects having to know about each other. Autoloads are Godot's version of singletons. The AnimationTree
node offers a state machine designed specifically for animations.
When should I consider writing or using programming patterns?When you use a general-purpose game engine, it already solves many problems for you. Godot is packed with features that limit the need for implementing many more patterns or thinking about them much.At GDQuest, we first think about code in the most concrete way possible and rely on Godot's core most essential concepts to solve the problem at hand: nodes, scenes, signals, resources, and scripts.We consider patterns when we cannot solve problems easily with Godot's tools. For example, if you need a lot of flexibility in your game's AI, you may want to use a behavior tree, which is a common pattern for complex AI in games.So, in general, you may consider design patterns when you find yourself writing a lot of code to solve a problem that seems like it should be simpler. Or, of course, if you know a pattern that fits your problem well and can save you time.
school.gdquest.com - 0.3.5-2024-11-01T20:19:19.321Z-06c546de2e802c845fb21e0c367cf9cc56c07f79-release