c# - Cross class/control calling - pass a reference, use events or change the structure -


i have long running background worker control exists part of main form. until now, worker's method hasn't had lot do. addition of new features , better error detection, within worker method, has meant has bloated little, number of methods have been extracted out of worker method.

the main job background worker does, execute methods on many instances of user control loaded , displayed in panel control. background worker , user controls children of main form. background worker getting quite large, thought time extract background worker (or @ least methods) own class make future changes easier, improve readability , simplify access data between background worker methods.

my question this, how should structure new class respect user controls , main form?

my thoughts have been...

  • to pass in references of user controls new class background worker begins. maintain parent-child-sibling relationships before don't know if passing ui element references non-ui class bad idea. not abstract.
  • use events within new class have main form execute methods in user controls. feels messy, unnecessary , easy break. abstract.
  • some how make new class parent of instances of user control. feel main form should parent of user controls both ui elements whereas new class have no ui elements. though feel offers better structure less abstraction (see below).

i think i'm struggling program hierarchy in terms of ui , function. display of controls more important function or other way round? feel function should abstract possible ui, ui fancy way of setting arguments in command-line program. think abstraction buzz philosophy @ moment (i've learned programming through micro-controllers doesn't count much.)

it's been long day , i'm not sure if of makes sense. please feel free correct me , i'll try clarify confusing. in advance.

i go first approach, , pass objects new class. pretty apply dependency injection suggests: http://en.wikipedia.org/wiki/dependency_injection


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -