samedi 24 octobre 2020

Share data across classess

I'm currently writing a program to read and parse ext2 filesystem C++. I split my program to a few classes, e.g. Ext2 as the main class, Superblock, etc. I have some data that I'll retreive once and I want it to be avilable to all the classes, e.g. block size, etc. What is the best way to achieve data sharing among several classes in a program without using globals (which I know are notorious)?

One way that crossed my mind is to keep those data bits as members in the main Ext2 class, and then pass reference to that instance to each class that needs to access this information via getter methods. Is there better way?

Aucun commentaire:

Enregistrer un commentaire