Theory question for C# gurus

T

Tim Mulholland

We have a user control with several other controls on it. We then have a
bunch of functions in the user control that operate on those controls.
In order to allow the user to invoke those functions, we have a "Breakaway"
form with several buttons on it.
When the user clicks those buttons, we want to invoke the correspoding
functions on the user control.

Two suggestions were made:
1) One developer suggested raising events from the breakway form and hooking
them into the functions on the user control.
2) Another developer suggested just passing the user control (technically a
reference i suppose) as a parameter to the constructor of the breakaway
form, and making the functions public so that the breakaway form could call
them.

Everyone agrees that the second suggestion just "feels" wrong. Maybe its all
those CS classes we took back in college.
But it would be significantly less code to do that.

What are the benefits to #1 over #2? We can't see any in our implementation
currently, but it still "feels" better.
Or are we all smoking something and there aren't any?

Thanks in advance,

-Tim
 
G

Guest

Not a guru, but I must say that #2 sounds ok to me. Especially when the
control is ment to be used only in your program.
 
W

William Stacey [MVP]

1) One developer suggested raising events from the breakway form and
hooking
them into the functions on the user control.
2) Another developer suggested just passing the user control (technically a
reference i suppose) as a parameter to the constructor of the breakaway
form, and making the functions public so that the breakaway form could call
them.

I like 2 also because methods are a lot easier (IMO) then hooking up a bunch
of events and delegates, etc. Events are also going to use (I think) the
thread pool to run the delegates, so more overhead.

If the form and control are same assembly, then make the functions Internal
so only your assem can see and call them. If not, then make the public
functions have some value to anyone using the control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top