I have a class "Parent". "Parent" class creates an object of class "Child" in my CPP module. The use-case is "Child" has to request for some information from "Parent". This can be done in several ways and I can think of the following designs.
1) Store object pointer/reference of "Parent" in "Child" and let "Child" call some public method of "Parent".
2) "Child" exposes an API to register callbacks. "Parent" registers a static function with "this" pointer as callback handle. When "Child" wants to request for information, it will call the registered callback function with callback handle as one of the arguments. The callback function will dereference the callback handle to "Parent" object and get the information.
Can someone tell me which is the better design? Also I would like to know is there any standard design for this type of problem?