473,581 Members | 2,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1684
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.co m

"davidw" <da****@affinis ys.com> wrote in message
news:ez******** ******@TK2MSFTN GP10.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.c om> wrote in
message news:e9******** *****@TK2MSFTNG P11.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.co m

"davidw" <da****@affinis ys.com> wrote in message
news:ez******** ******@TK2MSFTN GP10.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
1825
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 to the program. Where and how do I declare and initialise this object? For instance, it would have property implementation like this: ...
4
9163
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 two generated reports. When being generated, both reports will need to use the exact same data. The data are static strings and I plan to declare...
15
63814
by: DBA | last post by:
Hi All, What is the diff. between a singleton class and a static class in C#?
16
10096
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? Thanks a lot!
5
2642
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 object. Maybe better stated by example: public class SomeClassA { MySpecialObject A; public SomeClassA() { this.A = new MySpecialObject();
4
1405
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 example for using the singleton object. Regards, Srini
2
1783
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 singleton pattern in mind. The design pattern seems to be working properly (complex and simple variations of it) Serialzation/Deserialzation seems...
2
2619
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 improve the way to implement the Singlton Design Pattern. This is the way I used to do it: Singleton.h
3
2955
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 Singleton.__single
0
7876
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7804
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6563
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1144
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.