473,511 Members | 16,769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When to add a component versus a class

I'm sure this has been asked but after searching the Internet, I just can
find a clear answer. When should you add a component versus a class to you
Windows Forms application?

The timer is a good example. I'm planning to add a customer system.timer to
run that should be accessible from several forms so I don't want to use the
forms timer. Should I add this to a new class or new component?

Thanks,

John
Nov 20 '05 #1
8 1246
* "John Granade" <jo**@granade.net> scripsit:
I'm sure this has been asked but after searching the Internet, I just can
find a clear answer. When should you add a component versus a class to you
Windows Forms application?

The timer is a good example. I'm planning to add a customer system.timer to
run that should be accessible from several forms so I don't want to use the
forms timer. Should I add this to a new class or new component?


Class.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Cor
Hi John,

I would not write a timer in a seperate class.

It is totaly complete, there is nothing reusable by setting it in a seperate
class, why would you seperate it. (There are people who transporting there
car with a truck but most don't)

But would you make your own clock and you want to put that on more pages,
than that clock would hold a timer itself of course to let the indicator go
smooth and not eat up completly your system.

Just my 2 eurocents.

Cor
I'm sure this has been asked but after searching the Internet, I just can
find a clear answer. When should you add a component versus a class to you Windows Forms application?

The timer is a good example. I'm planning to add a customer system.timer to run that should be accessible from several forms so I don't want to use the forms timer. Should I add this to a new class or new component?

Nov 20 '05 #3
"Cor" <no*@non.com> wrote...
I would not write a timer in a seperate class.

It is totaly complete, there is nothing reusable by setting it in a seperate class, why would you seperate it. (There are people who transporting there
car with a truck but most don't)


Oops... keep in mind that reusability isn't the only goal. People transport
their car by "ship" all the time by the way, it's hard to drive a car made
in the UK, Germany or Italy to the US.

By encapsulating a generic timer within a specific timer class the behaviors
are guaranteed to be consistent across the application. ATimer.Reset()
would (regardless of who called it (or from where)) always reset ATimer to
the proper setting. If every routine can reset it a common timer to any
value it wants one of them will surely get it wrong.

Tom


Nov 20 '05 #4
Cor
Hi Tom,

I have thought about such a thing, but doing that I thought also if it is in
a project good if from everywhere a timer can be reseted.

But maybe there are circumstances and than I agree.

But I was knowing while writing this I was on slippery ground.

:-))

Cor
By encapsulating a generic timer within a specific timer class the behaviors are guaranteed to be consistent across the application. ATimer.Reset()
would (regardless of who called it (or from where)) always reset ATimer to
the proper setting. If every routine can reset it a common timer to any
value it wants one of them will surely get it wrong.

Nov 20 '05 #5
Cor
Hi Tom,

Maybe it is in the USA more normal, but I once was on a camping place in
Spain, and there was someone who had a campingcar in which he was
tranporting his car.

You know the distances in Europe, I found it funny to see.

Cor
Nov 20 '05 #6
Cor,

* "Cor" <no*@non.com> scripsit:
I would not write a timer in a seperate class.

It is totaly complete, there is nothing reusable by setting it in a seperate
class, why would you seperate it. (There are people who transporting there
car with a truck but most don't)


I am still not sure if the OP wants to /write/ a timer or if he wants to
/use/ an existing timer class.

Just my 2 Euro cents...

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #7
Hi Cor:

I'm not into "good or bad" :-) I think the guy said he needed it to be
accessible from many places. Despite that however it can be useful to
customize a timer class rather than remember to set a lot of common settings
every time you want one to be configured a particular way.

It's not entirely unlike a method that returns a connection string for
ADO.Net. One can always hardcode the string at the place it is used but
there is no advantage to doing that right? It makes it hard to change and
one of them will get messed up.

So if he needs a timer configured a standard way (even if it isn't accessed
globally) why not just ask for one preconfigured?

Tom
"Cor" <no*@non.com> wrote in message
news:eK**************@tk2msftngp13.phx.gbl...
Hi Tom,

I have thought about such a thing, but doing that I thought also if it is in a project good if from everywhere a timer can be reseted.

But maybe there are circumstances and than I agree.

But I was knowing while writing this I was on slippery ground.

:-))

Cor
By encapsulating a generic timer within a specific timer class the

behaviors
are guaranteed to be consistent across the application. ATimer.Reset()
would (regardless of who called it (or from where)) always reset ATimer to the proper setting. If every routine can reset it a common timer to any
value it wants one of them will surely get it wrong.


Nov 20 '05 #8
John,
The timer example aside.
I create a new Component when I want either a Visual Designer to help build
the class (by dragging & dropping other components onto it) or I want to
drag & drop this new Component onto another Visual Designer (such as another
Component or Form). Otherwise I create a Class.

I don't think I would create a new Component, just to drag a single
Component (System.Timer) onto it, unless that Component was easier to
configure from a Visual Designer then straight code.

Remember that Component is a Class that inherits from
System.ComponentModel.Component (more importantly they implement the
IComponent interface). The biggest benefit I see with Components is the
visual designer support in VS.NET.

Hope this helps
Jay

"John Granade" <jo**@granade.net> wrote in message
news:O8**************@TK2MSFTNGP10.phx.gbl...
I'm sure this has been asked but after searching the Internet, I just can
find a clear answer. When should you add a component versus a class to you Windows Forms application?

The timer is a good example. I'm planning to add a customer system.timer to run that should be accessible from several forms so I don't want to use the forms timer. Should I add this to a new class or new component?

Thanks,

John

Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2739
by: Martyn Lawson | last post by:
Hi, I am currently working as an Analyst on a .NET Web Project using ASP.NET and C#.NET. I have a couple of, at least what should be, quick questions: 1. My understanding of UML says that...
2
6140
by: David Williams | last post by:
I have a simple XML file that I have been using: <component name="test"> <class name="class"/> <component> Up till now, the Xpath of "//component/class" worked well to select the <class>...
2
6718
by: Andrew Robinson | last post by:
I need to create a shared static field for use within a number of different classes. Which one should I be using or are they all really the same thing? public class Widget { private Widget() {}...
0
974
by: David | last post by:
Hello I have made a component (MyWebForm) that inherits Page. This component have a method called 'ComponentAdded' that shows a msgbox if it is in design mode: Public Class MyWebForm Inherits...
0
1423
by: Jordan Bowness | last post by:
I make a similar post in another newsgroup, but this example is simplified somewhat. I have a component (cmpMyComponent) with 2 properties. The 1st property is a string value (Description) and...
9
7298
by: Don | last post by:
Is there any way to detect when an item has been added to the Items collection of a combobox or listbox? I am inheriting a Combobox and want to validate items before they are added to the...
122
7210
by: Edward Diener No Spam | last post by:
The definition of a component model I use below is a class which allows properties, methods, and events in a structured way which can be recognized, usually through some form of introspection...
7
2212
by: Joe | last post by:
Is it possible to have a component which is global to the entire application? I need to have a single component act sort of like a server which components in any of the forms can access. For...
1
5161
by: gary.bernstein | last post by:
Any idea why line 57 fails? http://rafb.net/p/86JdGg61.html gs = MyShutdown<Component, T1, T2, T3>(this); Errors: shutdown1.cpp: In constructor `Component<T1, T2, T3>::Component(int)':...
0
7355
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7423
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5066
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.