Connecting Tech Pros Worldwide Forums | Help | Site Map

When does it make sense to use static methods

Thirsty Traveler
Guest
 
Posts: n/a
#1: Apr 24 '06
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?



Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#2: Apr 24 '06

re: When does it make sense to use static methods


Thirsty Traveler <nfr@nospam.com> wrote:[color=blue]
> 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?[/color]

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

--
Jon Skeet - <skeet@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
Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
#3: Apr 24 '06

re: When does it make sense to use static methods


Him

"Thirsty Traveler" <nfr@nospam.com> wrote in message
news:u5VcZl8ZGHA.3524@TK2MSFTNGP04.phx.gbl...[color=blue]
>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?[/color]

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


Peter Bromberg [C# MVP]
Guest
 
Posts: n/a
#4: Apr 24 '06

re: When does it make sense to use static methods


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:
[color=blue]
> 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?
>
>
>[/color]
Thirsty Traveler
Guest
 
Posts: n/a
#5: Apr 25 '06

re: When does it make sense to use static methods


Both the bll and dal layers are stateless.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:eiRDQu8ZGHA.508@TK2MSFTNGP02.phx.gbl...[color=blue]
> Him
>
> "Thirsty Traveler" <nfr@nospam.com> wrote in message
> news:u5VcZl8ZGHA.3524@TK2MSFTNGP04.phx.gbl...[color=green]
>>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?[/color]
>
> 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
>[/color]


Thirsty Traveler
Guest
 
Posts: n/a
#6: Apr 25 '06

re: When does it make sense to use static methods


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]" <pbromberg@yahoo.nospammin.com> wrote in message
news:BEF937E9-F7A4-498E-AA30-A184250B2E0D@microsoft.com...[color=blue]
>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:
>[color=green]
>> 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?
>>
>>
>>[/color][/color]


Closed Thread


Similar C# / C Sharp bytes