Design Patterns
This blog will be about some of the programming patterns I use and have learned about.
Singleton
I have learned about singleton is a pattern used when you only want to have one instance of a class. It’s often used when you want global access to a class but only having one instance of it.
I used it for my audio manager when I wanted a script that had the audio collection you wanted to use it. I only wanted one instance of this class because I wanted to be able to play sounds from that collection from anywhere and I wanted all the sound in one place so you easily could access it and not having to have references in scripts everywhere to that audio manager.
Factory
Factory is a class that creates other objects . for example, a class that might create something like enemies, health packs or bullets. A factory can a lot of the time take care of complex configurations of the object it creates, factories are used to make it easier for you having all complex object instantiation in one place. Now I used this for my spawner I’m not sure if you can really call it a factory but it created wine objects and configured each of the wine bottles rigidbody adding velocity.
Observer
Observer is a class that is used when there are too many relationships between classes objects. A use for it in games would, for example, be an achievement system so the game might have an achievement that you would get from dying a 100 times now instead of having the code that makes the game show the achievement in the same class that keeps track of how many times you have died, you would have a script with all the different achievements and you would tell that script to call a function that notifies the game about the achievement.
Now I haven’t used an observer this much this year what I can remember I know that I used to have a sound manager with the code for all the different sounds in my previous games in scripting 1 and 2 and just call that script making it play the sounds but I don’t remember doing anything like it for studio 1.
References
Gamasutra.com. (2016). Design Patterns in Game Programming. [online] Available at: http://www.gamasutra.com/blogs/MichaelHaney/20110920/90250/Design_Patterns_in_Game_Programming.php [Accessed 25 Aug. 2016].
Gameprogrammingpatterns.com. (2016). Observer · Design Patterns Revisited · Game Programming Patterns. [online] Available at: http://gameprogrammingpatterns.com/observer.html [Accessed 25 Aug. 2016].