ME FIRST GAMES
Menu

games for me and you

What is a Singleton?

9/2/2020

0 Comments

 
Picture
The Singleton design pattern keeps the instantiation of a class to a single instance. Controversial but convenient, Singletons are something you will most definitely encounter in your life as a developer.
👍Singletons are very quick to implement and can make accessing an object easy.
👍Better than static classes, they can leverage polymorphism, cache values, and have their instances swapped out.
👍They require low memory usage, low latency, and only need one initialization.
👍In Unity, it offers better performance then FindObjectOfType.
👎Controlling initialization order across Singletons can become messy very quickly.
👎Deviates from the single responsibility principle.
👎Promotes mass coupling to a single instance.
👎It can be difficult to refactor, especially if you need to change its behavior in a different context.
👎In Unity, it is difficult to track the lifecycle of the Singleton MonoBehavior.
👎It's not always easy to subclass and extend.
👎Easy to abuse with many singletons and have limited flexibility in your codebase.
✅Do I recommend Singletons? Well, it depends...
✅Is your project small? Do you have time constraints? Will your class change in the future, or will it most likely always behave the same? e.g. logging system.
​
✅Singletons are not the cleanest or most flexible system, but they are convenient and quick to implement.
✅In Unity, Singleton MonoBehaviors can swap instances depending on what scene or prefab is loaded.
🚀Beware overuse, understand the limitations, and use it at your own discretion.
➡️Follow @mefirstgames for more game dev tips.
➡️Free Unity Tools: https://www.mefirstgames.com/hierarchy-comments.html 


0 Comments



Leave a Reply.

    Picture
    Me First Games is an independent game studio dedicated to creating unique and bizarre video games.
    GAMES HERE

    Red Matter

    Star Impact is an upcoming adventure platformer coming to PC, Mac, and Linux.

    Archives

    April 2021
    February 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    July 2020
    June 2020
    May 2020
    April 2019
    March 2019
    December 2018
    April 2018

    Categories

    All

    RSS Feed

Copyright (c) 2020 Me First LLC
  • STU the First AI
  • Blog
  • Contact
  • Unity Tools
    • Hierarchy Comments
  • STU the First AI
  • Blog
  • Contact
  • Unity Tools
    • Hierarchy Comments