Static classes: to use or not to use?

  • Thread starter Thread starter BLUE
  • Start date Start date
B

BLUE

I know it's a stupid question but...
I want to use a class that represents the current user of my application,
another one that reads position from a GPS receiver and another one that
reads RFID tags from a reader.
I don't want to create a new user each time a log in appens (only one login
at a time: mobile device) and I do not want to create a new object each time
I read position or a tag, so it's right to use static classes and to update
static fields (e.g. GPS.position or Tag.Id) every time a read happens?

Thank you.


Bye,
Luigi.
 
Hi,

BLUE said:
I know it's a stupid question but...
I want to use a class that represents the current user of my application,
another one that reads position from a GPS receiver and another one that
reads RFID tags from a reader.
I don't want to create a new user each time a log in appens (only one
login at a time: mobile device) and I do not want to create a new object
each time I read position or a tag, so it's right to use static classes
and to update static fields (e.g. GPS.position or Tag.Id) every time a
read happens?


Yes, it's ok.

Personally I would make the user a Singleton class. You will create an
instnce (and only one) at any moment.

The GPS & RFID classes should be static.
One thing you should pay especial attention is the events of these classes.
You may have more than one form that receive events from these classes. if
this is the case you will need to hook/unhook the handlers as you show/ihde
the forms.
 

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