lundi 23 décembre 2019

Good code design in C++ when objects interact with shared pointers holding data

I'm writing a C++ class say Class Foo that contains objects of Person class as well as a shared pointer of Data class, that holds a bunch of data for all Persons that can be accessed by personID.

I instantiate my Person objects as follows:

Person(uint32_t personID, std::shared_ptr<Data> data)

My Data class has a bunch of functions where I can access the Data by person ID.

The Data is set by class Foo and then I ensure that I call operations on that data after fresh data has been written to the Data class.

I'm pretty sure that this is bad design, but I'm not sure if there is a design pattern that turns this into good design.

Aucun commentaire:

Enregistrer un commentaire