473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Should I create my object with singleton pattern? thanks.

As I asked in last post, I want to put some logic in a object and all my
webcontrol instance will access that object, the object is responsed to
retrieve data from database if the data has not been retrieved yet. Vadym
Stetsyak suggested me to use singleton, it seems a good solution for me, but
after I read more about singleton, I find another issue - if I use singleton
patter, I can not store context data in the class anymore. How I used the
class is that I assigned required data to the class's variables, and then I
called methods in the class to get result. If I use singleton pattern, how
should I tell the called method what are those context data? Should I pass
all them by parameters? It seems there gonna be a lot of parameters passing
around this way.

If it is a problem, should I just let each webcontrol create their own
instance of the class? Will the performance be a lot worse this way? (the
class includes quite a few method functions).

Thanks.
Nov 15 '05 #1
2 1670
David,

Generally speaking, if a class has a number of methods on it, it's not
going to impact performance as much as the data contained in instances of
the class. For example, having 10 methods on a class isn't the same as
having an array with 2048 elements in it (you pick the type, it still gets
large).

As for your singleton, what kind of contextual data are you trying to
store? I think this will help determine what you need to do. If the
context is the current user of your web application, then I would create an
instance and place it in the Session, and then it will be around for as long
as the server process is processing requests from that user.

If it is another kind of context, then you have to make that
determination (when a new one is created, etc, etc), and manage that
yourself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"davidw" <da****@affinisys.com> wrote in message
news:ez**************@TK2MSFTNGP10.phx.gbl...
As I asked in last post, I want to put some logic in a object and all my
webcontrol instance will access that object, the object is responsed to
retrieve data from database if the data has not been retrieved yet. Vadym
Stetsyak suggested me to use singleton, it seems a good solution for me, but after I read more about singleton, I find another issue - if I use singleton patter, I can not store context data in the class anymore. How I used the
class is that I assigned required data to the class's variables, and then I called methods in the class to get result. If I use singleton pattern, how
should I tell the called method what are those context data? Should I pass
all them by parameters? It seems there gonna be a lot of parameters passing around this way.

If it is a problem, should I just let each webcontrol create their own
instance of the class? Will the performance be a lot worse this way? (the
class includes quite a few method functions).

Thanks.

Nov 15 '05 #2
Thanks.

I think the number of method doesn't matter too. In my case, the class need
read style data to decide how to display the webcontrol, let's assume there
are 100+ styles, when one user use one style, and the style data is not in
the class, it will read it from database and keep it for other users' call.
So I am looking for a centrol place to maintain the style data, doesn't that
make sense?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:e9*************@TK2MSFTNGP11.phx.gbl...
David,

Generally speaking, if a class has a number of methods on it, it's not
going to impact performance as much as the data contained in instances of
the class. For example, having 10 methods on a class isn't the same as
having an array with 2048 elements in it (you pick the type, it still gets
large).

As for your singleton, what kind of contextual data are you trying to
store? I think this will help determine what you need to do. If the
context is the current user of your web application, then I would create an instance and place it in the Session, and then it will be around for as long as the server process is processing requests from that user.

If it is another kind of context, then you have to make that
determination (when a new one is created, etc, etc), and manage that
yourself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"davidw" <da****@affinisys.com> wrote in message
news:ez**************@TK2MSFTNGP10.phx.gbl...
As I asked in last post, I want to put some logic in a object and all my
webcontrol instance will access that object, the object is responsed to
retrieve data from database if the data has not been retrieved yet. Vadym Stetsyak suggested me to use singleton, it seems a good solution for me, but
after I read more about singleton, I find another issue - if I use

singleton
patter, I can not store context data in the class anymore. How I used the class is that I assigned required data to the class's variables, and then I
called methods in the class to get result. If I use singleton pattern,

how should I tell the called method what are those context data? Should I pass all them by parameters? It seems there gonna be a lot of parameters

passing
around this way.

If it is a problem, should I just let each webcontrol create their own
instance of the class? Will the performance be a lot worse this way? (the class includes quite a few method functions).

Thanks.


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mark Neilson | last post by:
1. What is the best way to make a single instance of my top level class (DLL) internally available to all other members of the assembly? The top level object is where all other access is made in...
4
by: James N | last post by:
Here's the situation: I have 3 webforms in my project. Form 1 allows the user to select a type of report to generate. There are 2 possible type of reports, and therefore, Forms 2 and 3 are these...
15
by: DBA | last post by:
Hi All, What is the diff. between a singleton class and a static class in C#?
16
by: Elad | last post by:
Hi, I have an application that is made up of several executables. I need all these executables to use the same instance of an object. What is the best, most efficient way to approach this? ...
5
by: Christopher D. Wiederspan | last post by:
This is a bit tough to figure out the best way to ask, but here it goes. I've got a class, say MyObject, and everytime this class is instanciated, I actually want to get a reference to an existing...
4
by: Srini | last post by:
Hi , Can anyone tell me when I can use singleton pattern. Will it be good for implementing the dataaccess Layer. Will it be usefull for the buisness object layer . Could you give me a practicle...
2
by: Chris Murphy via DotNetMonster.com | last post by:
Hey guys, I've been hitting a brick wall with a problem I've come accross in developing an application. Background: The application uses one primary class that I'm trying to implement with the...
2
by: Daniel Kay | last post by:
Hello, currently I am reading the book "Effective C++ Third Edition" from Scott Meyers. While Reading Item 4 (Make sure that objects are initialized before they're used) I got an idea how to...
3
by: dischdennis | last post by:
Hello List, I would like to make a singleton class in python 2.4.3, I found this pattern in the web: class Singleton: __single = None def __init__( self ): if Singleton.__single: raise...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.