Skip to main content
added 159 characters in body; edited tags
Source Link

For context, I'm building a GTK+ application in C where a subclass of GtkApplicationWindow creates and displays a subclass of GtkToolbar and a GtkNotebook (a widget with multiple pages that can be displayed alternately by a member function). There are radio buttons on the toolbar to switch among the pages.

Should the toolbar hold a (duplicate) reference to the notebook (provided by the window during construction), or should it only hold a reference to its owner (the window) and call a function of its owner which in turn calls the notebook's function to switch pages? Another alternative, the toolbar might only keep a reference to window, and access the window's reference of the notebook each time it wishes to toggle pages? I have a feeling this is a case addressed by the Law of Demeter, but I'm not sure what it dictates.

For context, I'm building a GTK+ application in C where a subclass of GtkApplicationWindow creates and displays a subclass of GtkToolbar and a GtkNotebook (a widget with multiple pages that can be displayed alternately by a member function). There are radio buttons on the toolbar to switch among the pages.

Should the toolbar hold a (duplicate) reference to the notebook (provided by the window during construction), or should it only hold a reference to its owner (the window) and call a function of its owner which in turn calls the notebook's function to switch pages? I have a feeling this is a case addressed by the Law of Demeter, but I'm not sure what it dictates.

For context, I'm building a GTK+ application in C where a subclass of GtkApplicationWindow creates and displays a subclass of GtkToolbar and a GtkNotebook (a widget with multiple pages that can be displayed alternately by a member function). There are radio buttons on the toolbar to switch among the pages.

Should the toolbar hold a (duplicate) reference to the notebook (provided by the window during construction), or should it only hold a reference to its owner (the window) and call a function of its owner which in turn calls the notebook's function to switch pages? Another alternative, the toolbar might only keep a reference to window, and access the window's reference of the notebook each time it wishes to toggle pages? I have a feeling this is a case addressed by the Law of Demeter, but I'm not sure what it dictates.

Source Link

Should an object keep a reference to a sibling object, or access through mutual owner's method

For context, I'm building a GTK+ application in C where a subclass of GtkApplicationWindow creates and displays a subclass of GtkToolbar and a GtkNotebook (a widget with multiple pages that can be displayed alternately by a member function). There are radio buttons on the toolbar to switch among the pages.

Should the toolbar hold a (duplicate) reference to the notebook (provided by the window during construction), or should it only hold a reference to its owner (the window) and call a function of its owner which in turn calls the notebook's function to switch pages? I have a feeling this is a case addressed by the Law of Demeter, but I'm not sure what it dictates.