mercredi 14 avril 2021

Is there a design pattern to deal with when every object needs one particular object's data?

I've got a dilemma in an OOP program: every object needs to access the data stored in one object (call it X). Currently I've got X as a global variable and every other object can simply reference X, but I don't think this is ideal.

Is there a design pattern to deal with this?

The closest I've come is the Observer Pattern but it requires a local copy of X in each individual object, which eats up massive amounts of memory.

Aucun commentaire:

Enregistrer un commentaire