samedi 24 octobre 2020

Should I use singleton?

I am writing a C++ program that can read and process info of a ext2 filesystem. I figured that I should create a class named Device that will hold the file descriptor of the device and provide a method for reading from the device. An instance of this class should be instantiated once in the beginning of the program and used across multiple classes, e.g. BlockGroup, SuperBlock, etc.

Logically I shouldn't have more then one instance of this Device class, and that's a pro to use singleton. But I wonder: What risk am I taking if i don't use singleton, and just make sure that I create only one instance of this class across my application?

Aucun commentaire:

Enregistrer un commentaire