is using static ok here ?

  • Thread starter Thread starter Coaster
  • Start date Start date
C

Coaster

Greetings,

I think I know but am unsure here. I have libraries for business and data
layers and originally designed most functions to be static methods like so

public static somedataobject BLL_CheckMyNumber(passed_in_user_data)
{
return DAL_CheckMyNumber(passed_in_user_data)
}

this is called from a web application I've been developing.

My questions is, if two people call this at the same time will both calls
clash in some way or are both instances completely separate?

I think the latter but want to be sure.

thanks
 
Coaster said:
I think I know but am unsure here. I have libraries for business and data
layers and originally designed most functions to be static methods like so

public static somedataobject BLL_CheckMyNumber(passed_in_user_data)
{
return DAL_CheckMyNumber(passed_in_user_data)
}

this is called from a web application I've been developing.

My questions is, if two people call this at the same time will both calls
clash in some way or are both instances completely separate?

I think the latter but want to be sure.

The code posted is thread safe itself.

But whether DAL_CheckMyNumber is thread safe we can not say.

One problem with the static method approach is that you can
expose an interface an use different implementations.

Arne
 
Coaster said:
Greetings,

I think I know but am unsure here. I have libraries for business and data
layers and originally designed most functions to be static methods like so

public static somedataobject BLL_CheckMyNumber(passed_in_user_data)
{
return DAL_CheckMyNumber(passed_in_user_data)
}

this is called from a web application I've been developing.

My questions is, if two people call this at the same time will both calls
clash in some way or are both instances completely separate?

I think the latter but want to be sure.

The 2 function calls are independant of each other in that both will have
their own copy of passed_in_user_data. The calls will not conflict unless
you try to access the same data somewhere such as a module level or global
variable
 
Arne Vajhøj said:
The code posted is thread safe itself.

But whether DAL_CheckMyNumber is thread safe we can not say.

One problem with the static method approach is that you can
expose an interface an use different implementations.

Arne

Thanks, can you explain this last part
One problem with the static method approach is that you can
expose an interface an use different implementations.

a little more. I understand how interfaces can expose different
implementations but not sure how making it static is problematic.
 
Coaster said:
a little more. I understand how interfaces can expose different
implementations but not sure how making it static is problematic.

Interfaces can not have static methods.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top