473,402 Members | 2,046 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,402 software developers and data experts.

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 6499
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
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
by: Tom | last post by:
This is not intuitivelly clear.
3
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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
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...

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.