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

Home Posts Topics Members FAQ

When does it make sense to use static methods

I am still a little confused on when it makes sense to use static methods.
For example, if we have a web page that calls a business logic layer that
calls a data access layer, should the method calls be static if no data is
stored as state in the components?
Apr 24 '06 #1
5 6505
Thirsty Traveler <nf*@nospam.com> wrote:
I am still a little confused on when it makes sense to use static methods.
For example, if we have a web page that calls a business logic layer that
calls a data access layer, should the method calls be static if no data is
stored as state in the components?


That's basically it - if it doesn't operate on the state of any
particular object, it makes sense to be static.

--
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
Apr 24 '06 #2
Him

"Thirsty Traveler" <nf*@nospam.com> wrote in message
news:u5**************@TK2MSFTNGP04.phx.gbl...
I am still a little confused on when it makes sense to use static methods.
For example, if we have a web page that calls a business logic layer that
calls a data access layer, should the method calls be static if no data is
stored as state in the components?


Yes, a method should be static IF it does not depend of any of the state
info of the instance and is bounded to the class itself.

Btw, when you refer to components that does not store status, r u talking
about your business or data layer?

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Apr 24 '06 #3
I think conceptually, the key question to ask is "could my system ever use
more that one of these objects?". If it's a "Customer" class, obviously the
answer would be yes, and you wouldn't want static there.

However if you take a look at something like the ADO.NET v2 "SqlHelper"
class from the Application Blocks, every method in that is static. In fact,
the SqlParameterCache in it has to be static, since it's caching your
SqlParameters for you.

Hope that helps.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Thirsty Traveler" wrote:
I am still a little confused on when it makes sense to use static methods.
For example, if we have a web page that calls a business logic layer that
calls a data access layer, should the method calls be static if no data is
stored as state in the components?

Apr 24 '06 #4
Both the bll and dal layers are stateless.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:ei*************@TK2MSFTNGP02.phx.gbl...
Him

"Thirsty Traveler" <nf*@nospam.com> wrote in message
news:u5**************@TK2MSFTNGP04.phx.gbl...
I am still a little confused on when it makes sense to use static methods.
For example, if we have a web page that calls a business logic layer that
calls a data access layer, should the method calls be static if no data is
stored as state in the components?


Yes, a method should be static IF it does not depend of any of the state
info of the instance and is bounded to the class itself.

Btw, when you refer to components that does not store status, r u talking
about your business or data layer?

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Apr 25 '06 #5
We do store objeects such as this in session state on the web server. The
BLL and DAL layers are stateless and load balanced.

I am wondering about threading. If there are multiple concurrent users
logged into the web app, will they be single threaded through the bll/dal
layers?

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:BE**********************************@microsof t.com...
I think conceptually, the key question to ask is "could my system ever use
more that one of these objects?". If it's a "Customer" class, obviously
the
answer would be yes, and you wouldn't want static there.

However if you take a look at something like the ADO.NET v2 "SqlHelper"
class from the Application Blocks, every method in that is static. In
fact,
the SqlParameterCache in it has to be static, since it's caching your
SqlParameters for you.

Hope that helps.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Thirsty Traveler" wrote:
I am still a little confused on when it makes sense to use static
methods.
For example, if we have a web page that calls a business logic layer that
calls a data access layer, should the method calls be static if no data
is
stored as state in the components?

Apr 25 '06 #6

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

Similar topics

11
2147
by: Noah Coad [MVP .NET/C#] | last post by:
How do you make a member of a class mandatory to override with a _new_ definition? For example, when inheriting from System.Collections.CollectionBase, you are required to implement certain...
17
51398
by: Tom | last post by:
This is not intuitivelly clear.
3
22367
by: Dave | last post by:
Hi, Is there a general rule to use 'static' on a class member? It seems uneccessary to have to create an instance of an object just to use it's methods where declaring something as static makes...
8
2046
by: Fernando Lopes | last post by:
Hi there! Someone has some code sample about when is recommend use a statis method? I know this methos don't want to be initialized and all but I want to know when I need to use it. Tks....
18
1951
by: cj | last post by:
members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe. I'm under the impression before you can use a class you have to make an...
11
3220
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
6
2606
by: =?Utf-8?B?Sko=?= | last post by:
I have a logger component that logs to multiple sources, ie textfile, eventlog etc. and I have two methods that depending on where I call up my logger comp. one of them will be called. For ex. if...
14
3767
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
0
2178
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7353
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
7418
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...
1
7075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7508
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
5662
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
5063
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
1572
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.