mardi 7 avril 2015

C++ Parent / Child class dependencies

I am looking for some ideas:


Suppose a parent class "Cparent". The parent class contains a list of children.


Childen want to send data, but the link with the outside world is the parent.


What are common design patterns for this setup:


Option 1 Provide children with a pointer/ref to the parent, but in this case there is close coupling between children and parent. Children need to know the parents structure.


Option 2 Set a callback "sendData()" at the children.


Option 3 Let the children derive from a class which informs the parent.


What are common design patterns to accomplish this while letting the child know as less as possible about the parent ?


Aucun commentaire:

Enregistrer un commentaire