Lets say we have an event handler function which clears the Model data when a user hits the Clear Button:
Code: Select all
void MAIN_FRAME::OnButtonClick_ClearModelData( wxCommandEvent& WXUNUSED( event ) )
{
//---------------- | CLEAR LOG DATA |----------------
........................
........................
Clear Model Data
}
And, we have 3 other event handler functions, which react to different events and do different stuff, but also want to clear the Model Data as part of their work.
Code: Select all
void MAIN_FRAME::OnSomeEvent1( wxCommandEvent& WXUNUSED( event ) )
{
//---------------- | CLEAR LOG DATA |----------------
........................
........................
Clear Model Data
}
void MAIN_FRAME::OnSomeEvent2( wxCommandEvent& WXUNUSED( event ) )
void MAIN_FRAME::OnSomeEvent3( wxCommandEvent& WXUNUSED( event ) )
---
Yes, we could have a separate, non-handler function which does the work of actually clearing the Model data, this function can then be called by any event handler functions or any other UI functions that need to clear the Model data:
My aversion to this design is because it essentially duplicates the purpose of OnButtonClick_ClearModelData(), implementing 2 functions which do the same task, I'm not convinced this is good coding practice, adding proxy functions makes the source page longer and more complicated than it has to be.
....if we already have a function that does the task we need, then why not just call that function, thus re-using existing code instead of adding unnecessary complexity? The handler function can be called directly or via the event handler system by manually pushing an event.
If we're going to add complexity to our code we should have a good reason for doing so, right?
Is this essentially a style issue or is there a technical reason for going one way or the other?
wxWidgets(v3.2.2.1) - Vs2022(v143) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)