Singleton
A singleton pattern is a class that instantiates an object one time. So instead of using a globally defined object, you can use a static variable in your singleton class. That way the object will only have one instance. Hence the word "Singleton", "single". Get it?
Facade
A facade pattern is a set of classes interact with each other in a subsystem. Only one class exchanges data with another class within another subsystem containing interactive classes.
State
State patterns is like a using switches() and enums. It's like having a group of code do its own set of instructions. In the end, you will eventually merge the states together by calling them in an update().
This decreases the amount of errors which occur in your program.
Factory
A factory pattern is a single point of a class entrance for the creation objects. It's just like an actual factory that builds many of the same products. When it is ready to be manufactured it is shipped to its location. The same thing is with a factory pattern, it creates many objects for specific function. Factory pattern is also good for organizing memory allocation.
Design patterns are a very good practice to use especially if you like order and neatness in your code. You can use these kinds of patterns to further improve your programming style.
No comments:
Post a Comment