I have a question on how to structure the code regarding GUI objects. Suppose I have a dialog in which there is a list control that contains a bunch of names retrieved from the database. User can edit names. Does logic exist inside this dialog class or should it be externally. To illustrate what I mean, there is some kind of pseudo-code showing the structure of the code when the logic is processed outside the dialog class:
NamesDialog : wxDialog { Private: ..stuff.. Public: ... SetNames(wxStringArray names); wxStringArray GetNames(); ..stuff.. }
This way the class user will do something like:
wxStringArray names = DatabaseManager::Get()->GetNames(); names.Sort(); NamesDialogObject.SetNames(names); NamesDialogObject.ShowModal(); wxStringArray modified_names = NamesDialogObject.GetNames(); AddToDatabase(modified_names);
On the other hand, the database logic may be located inside the NamesDialog class itself. In the show method, I can query the database for names and, when the user interacts with the controls (in this case, list management), the database can be updated from event handlers. As a result, the NamesDialog class has only the Show () method, since there is no need to use SetNames or GetNames (), etc.
Which method is usually preferable? I don't have much work experience, so I'm not sure if this is the right way to handle this. Sometimes it's easier to handle everything in a class, but accessing the objects it interacts with can be tricky. This can usually be done if the corresponding objects are the same as the database manager in the above example.
hd112 source share