473,321 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Design Decision - Static vs. Non Static Classes

In consideration of a "Utilities" class that contains methods intended to be
used amongst multiple projects...

Is there any general consensus on whether such a class should be static? I
have traditionally and somewhat thoughtlessly created these sorts of classes
as static... but now that I'm refactoring a number of apps written over the
past few years I'd like to make a good decision on this particular issue.

And yes - I know there is no "right vs. wrong" way to go here - so I'd
appreciate some considerations both for and against static classes (in the
case of utilities or DAL).

Thanks
Aug 21 '07 #1
6 1565
Hi,

"Smithers" <A@B.comwrote in message
news:eg*****************@TK2MSFTNGP05.phx.gbl...
In consideration of a "Utilities" class that contains methods intended to
be used amongst multiple projects...

Is there any general consensus on whether such a class should be static? I
have traditionally and somewhat thoughtlessly created these sorts of
classes as static... but now that I'm refactoring a number of apps written
over the past few years I'd like to make a good decision on this
particular issue.
Well, take a look at how those "utilities" classes are defined in the
framework, take a look at for example Math, File, Directory, Environment,
etc


Aug 21 '07 #2
It depends. If the class functions can be used as standalone with no
internal data that has to hang around then static works well. On the other
hand, if the class will have data members that will hang on to information
between method calls then static is probably not such a good idea.
--
Richard Lewis Haggard
General: www.Haggard-And-Associates.com

Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm
"Smithers" <A@B.comwrote in message
news:eg*****************@TK2MSFTNGP05.phx.gbl...
In consideration of a "Utilities" class that contains methods intended to
be used amongst multiple projects...

Is there any general consensus on whether such a class should be static? I
have traditionally and somewhat thoughtlessly created these sorts of
classes as static... but now that I'm refactoring a number of apps written
over the past few years I'd like to make a good decision on this
particular issue.

And yes - I know there is no "right vs. wrong" way to go here - so I'd
appreciate some considerations both for and against static classes (in the
case of utilities or DAL).

Thanks

Aug 21 '07 #3
And how would the use of delegates affect the use of the utility class
members?

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
"Richard Lewis Haggard" <HaggardAtWorldDotStdDotComwrote in message
news:O$**************@TK2MSFTNGP03.phx.gbl...
It depends. If the class functions can be used as standalone with no
internal data that has to hang around then static works well. On the other
hand, if the class will have data members that will hang on to information
between method calls then static is probably not such a good idea.
--
Richard Lewis Haggard
General: www.Haggard-And-Associates.com

Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm
"Smithers" <A@B.comwrote in message
news:eg*****************@TK2MSFTNGP05.phx.gbl...
>In consideration of a "Utilities" class that contains methods intended to
be used amongst multiple projects...

Is there any general consensus on whether such a class should be static?
I have traditionally and somewhat thoughtlessly created these sorts of
classes as static... but now that I'm refactoring a number of apps
written over the past few years I'd like to make a good decision on this
particular issue.

And yes - I know there is no "right vs. wrong" way to go here - so I'd
appreciate some considerations both for and against static classes (in
the case of utilities or DAL).

Thanks


Aug 22 '07 #4
clintonG wrote:
And how would the use of delegates affect the use of the utility class
members?
From the perspective of keeping everything involved in the process
inside the method, I don't really see any issues doing it this way -- as
long as the delegate itself follows the same rule and only tries to act
on things it has been provided. You might get into threading issues if
you try and do anything beyond that.

Chris.
Aug 22 '07 #5
On 2007-08-21, Smithers <A@B.comwrote:
Is there any general consensus on whether such a class should be static? I
have traditionally and somewhat thoughtlessly created these sorts of classes
as static... but now that I'm refactoring a number of apps written over the
How do you want to test the class? And how would you test stuff that
uses these static methods? (Mocking seems hard to achieve)
--
Kind regards,
Tim Van Wassenhove <url:http://www.timvw.be/>
Aug 22 '07 #6
Tim Van Wassenhove <ti***@newsgroup.nospamwrote:
Testing the static method itself isn't that hard. Testing methods that
use this static method is what can become difficult.
Indeed, if it's doing something complicated or using an external
resource. In that case it's often worth encapsulating the behaviour in
an interface and using dependency injection or a replacable factory
etc.

Most static classes I've written haven't included such behaviour,
however - they've been simple utility methods.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 23 '07 #7

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

Similar topics

4
by: Danimal | last post by:
I have been using PHP for a long time... since it was called PHP/FI. I have a programming design question: Let say I have this class: class attrib { var $lenght; var $type; ... }
36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
3
by: Omer van Kloeten | last post by:
The Top Level Design: The class Base is a factory class with a twist. It uses the Assembly/Type classes to extract all types that inherit from it and add them to the list of types that inherit...
11
by: Arsen Vladimirskiy | last post by:
Hello, If I have a few simple classes to represent Entities such as Customers and Orders. What is the proper way to pass information to the Data Access Layer? 1) Pass the actual ENTITY to...
3
by: Amadelle | last post by:
Hi All and thanks in advance, I wanted to know when is a good idea to use a static class (with static constructor) and when to use instance classes? I have read couple of articles on line and...
4
by: news.microsoft.com | last post by:
Hello, I've got a design problem that I can't figure out. I need to override a static method which happens to be referenced by methods inside nested classes. In the sample below, in the call...
20
by: Brad Pears | last post by:
I am completely new to vb .net. I am using visual Studio 2005 to redo an Access 2000 application into a .net OO application using SQL Server 2000 - so a complete rewrite and re-thinking of how...
9
by: Grizlyk | last post by:
Somebody have offered std colors to C++ in the msg here: http://groups.google.com/group/comp.lang.c++/browse_frm/thread/2e5bb3d36ece543b/1acf6cd7e3ebdbcd#1acf6cd7e3ebdbcd The main objection to...
4
by: =?Utf-8?B?Um9i?= | last post by:
I've a number of objects (classes) defined in an application which I'm using to model packets on a network. I have a class hierarchy of Packet (inherited by) EthernetPacket (inherited by) IPPacket...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.