c# - Change Code Behaviour depending on Context -


i have class can called either gui or form non-graphical environment (batch mode)

what convenient best practice way "tell" gui-related parts of code not execute when executed in batch mode.

i think of like

    public mymethod()     {                     [@tag: dothis_only_if_guimode]         showpanels();         ....     } 

and gui_mode_activated set true or false on runtime somewhere, depending on program called from

i want avoid ugly tracing if/else stuff scattered on code.
little thumb tells me aop way go (but if manage find simpler alternative i'll go it)
so, simplest , straightforward way ?

update: as contributors pointed out, separating gui code business code rule of thumb, still interested in knowing ways if no gui involved (ie, 2 different batch modes 2 different environments, example)

i think best bet take gui-specific code out of class , implement events triggered @ key times in class's processing. when called gui, gui code subscribes events , 'does right thing.' batch-code ignores events , well.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -