P
phl
hello,
My project in a web project. I choose to use singleton in one of my
projects. Towards the end I realise that I seemed to have refered to
the fields singleton in my other classes in my business logic a little
precariously. I access my the fields in the singlton in my BLL classes
directly. Is this a really bad violation of OOP rules? It's almost liek
I have use the singlton as one big global variable. Is there any decent
way of using singltons, how do most people use them?
Why I choose singleton to represent some of my data is that, I need to
have say a class that represent user information, that other classes
can access, without having to instaniate a user info class everytime(as
this is a web app in .net, users settings die every post back if you
don't explicitly hold it in memory. I know I could have a base class
with userinfo instead but it would have to be instaniated everytime or
have userobject held in a session variable some where). Using singltons
reminds me of programming in the old days (liek C) where you pass whole
structures to functions, except singltons are lot easier.
So Have I completely abuse the singlton, should I have at least pass
the values of the singlton as my class constructor parameters, instead
of accessing them directly? is there a better way of doing this?
Cheers
My project in a web project. I choose to use singleton in one of my
projects. Towards the end I realise that I seemed to have refered to
the fields singleton in my other classes in my business logic a little
precariously. I access my the fields in the singlton in my BLL classes
directly. Is this a really bad violation of OOP rules? It's almost liek
I have use the singlton as one big global variable. Is there any decent
way of using singltons, how do most people use them?
Why I choose singleton to represent some of my data is that, I need to
have say a class that represent user information, that other classes
can access, without having to instaniate a user info class everytime(as
this is a web app in .net, users settings die every post back if you
don't explicitly hold it in memory. I know I could have a base class
with userinfo instead but it would have to be instaniated everytime or
have userobject held in a session variable some where). Using singltons
reminds me of programming in the old days (liek C) where you pass whole
structures to functions, except singltons are lot easier.
So Have I completely abuse the singlton, should I have at least pass
the values of the singlton as my class constructor parameters, instead
of accessing them directly? is there a better way of doing this?
Cheers