Assume I have a main window. The main window has some child windows, including a log window to log what happens and a number of operating windows to operate a user's data. After each operation in the operating window, I want to log it in the log window. There are several ways to implement it.
Put a pointer pointing to the log window in the operating windows. To do this, I think the operating window is not so reusable since it is bound to a pointer. Someday if I don't want logging, I need to delete it. Also, this way may take a little more memory. In addition, if the operating window is the main window's child's childe's child..., I need to transfer the pointer inside one by one.
Make the main window to be a singleton and add a public log function to it. When I need logging, I just call like MainWindow::Inheritance()->Log(theInformation). But what happens if someday I have 2 main windows.
Any good suggestion for the problem. Thanks a lot!