Sunday 15 March 2015

c++ - How do I avoid using a global for the data behind a GUI? -


I am writing an audio processing standalone application. I have an audio manager object that does things with engines (like I / O device management, signal processing routing, running state). I am writing a GUI to control the AudioManager running in the background. Currently, each component needs to give a message to AudioManager , for an indicator Required.

It begins to go crazy when the dark nested object requires an indicator in the AudioManager , because it means that I want to point the pointer through the constructor of the GUI objects Have to pass, take care directly about T AudioManager (only some sub-compilers need to know).

I can make only one button to avoid the boilerplate, but the information flow is bidirectional from the classroom, so it's probably a bad idea to make me feel a little confused The evidence seems to be wrapping everything in a large classroom, but it makes it a bit easier to pass about, is there a similar pattern to avoid being able to pass a goof-up?

Below are some pseudo-code shown, in which there are some types of structures, which highlight the basic type of problem. I tagged this C ++ 11, to see if it gives a unique solution.

  main window () {am = new AudioManager (); SomeWidget = new SomeWidget (am); } SomeWidget (AudioManager * am_) / / SomeWidget really does not care {someSubComponent = new SubThingy (am_); } Subhingtoning (Audio-Manager * M_): SublingloloLoco Audio ManagerSraft (AMI) {Subhthingale Lok Academy Manager- gt; Register AsomingOper Other (this); In your example, "SomeWidget" should take actual dependency, "SomeThingy," some examples "" are not an audio manager.  

Usually when you reference a classroom to the whole world, it means that the class does a lot. The name "XyzManager" usually indicates a problem for the same reason. (The classes should be named on the basis of their name, and if the most specific name is available which describes what it does "manage", then it should be different classes) < / Html>

No comments:

Post a Comment