Static or not Static

S

shapper

Hello,

I have a few services on my application.
Usually most of Microsoft ASP.NET services are static.
Because of this I tend to associate a service as static and
repositories as non static and if possible to be used in a Unit of
Work pattern to be able to apply many methods and commit at the end.

Should I make my services and their methods static?

Usually I use my services methods only once. For example:
MailService.SendMessage(...)
or
MembershipService.SignIn(....)

Isn't this a condition to make them static?

Thank You,
Miguel
 
G

Göran Andersson

shapper said:
Hello,

I have a few services on my application.
Usually most of Microsoft ASP.NET services are static.
Because of this I tend to associate a service as static and
repositories as non static and if possible to be used in a Unit of
Work pattern to be able to apply many methods and commit at the end.

Should I make my services and their methods static?

Usually I use my services methods only once. For example:
MailService.SendMessage(...)
or
MembershipService.SignIn(....)

Isn't this a condition to make them static?

Thank You,
Miguel

A method should be static if it doesn't need any class instance to run
in. If it doesn't use any instance data from it's class, it should be
static so that you don't have to create a dummy object just to call the
method.
 
S

shapper

A method should be static if it doesn't need any class instance to run
in. If it doesn't use any instance data from it's class, it should be
static so that you don't have to create a dummy object just to call the
method.

That sounds logic and adequate to what I was doing ...
But then I realized that a static class cannot implement an interface
which I was doing.
I am not sure why ... But I think I probably will keep non static.
 

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

Top