This looks like the Factory Pattern, where you define an additional MFactory
class, that holds a pointer to M
, and a getter method M* getM()
. When the Cx
classes need the M
instance, they query MFactory
for that instance using getM()
. The instance then is created, if it hasn't been already. What this design may miss is to allow only Cx
classes to query MFactory
, but from the description I conclude that this is not a hard requirement here.
Another issue is how to define which Cx
classes use which M
instance, thus, which exact factory object they query. This factory class may be a singleton, but then all the Cx
class sets are going to share the same model (which is probably not your intent). OR, each set may share one model (and thus one MFactory
). One more possible implementation is to have a factory create the whole Cx
set and initialize it with the same model object, and make sure that Cx
are created only via that factory.