473,738 Members | 8,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Global" Dataset - Singleton

Hallo,

hello, i try to implement a global dataset - singleton based.

On www.bakterienforum.de i found a singleton implementation:

sealed class SingletonCounte r
{
public int Counter = 0;

private SingletonCounte r(){}
public static readonly SingletonCounte r Instance = new
SingletonCounte r();
}

Can i use this for implementing the global dataset and how can i do this?

Thank you in advance.

hans
Sep 9 '06 #1
8 8031
I usually recommend the following article on the Singleton pattern.

http://www.yoda.arachsys.com/csharp/singleton.html

However I don't think you are looking for a Singleton, you just want a
static dataset, right?
So you just need to declare:

public class SomeClass
{
private static DataSet globalDataSet = new DataSet();

public static DataSet GlobalDataSet
{
// TODO: Implement locking if using multiple threads
get{return globalDataSet;}
}
}

Then you can get access to the dataset by stating:

SomeClass.Globa lDataSet

However, a static dataset sounds absolutely hideous to me and I think you
might be misunderstandin g the concepts of OOP if you are looking to use one.
Singleton items are usually for objects or services that you only ever want
1 of in existence, for example an object that handles the database or
possibly uses a lot of resources (i'm sure there are loads of other good
reasons too).
Datasets are usually just currency that move between architectural tiers
there is hardly ever reason to make static ones.
Could I ask what exactly do you need this static dataset for?

HTH

Simon

"Hans Greif" <un*@cubs.dewro te in message
news:4m******** ****@individual .net...
Hallo,

hello, i try to implement a global dataset - singleton based.

On www.bakterienforum.de i found a singleton implementation:

sealed class SingletonCounte r
{
public int Counter = 0;

private SingletonCounte r(){}
public static readonly SingletonCounte r Instance = new
SingletonCounte r();
}

Can i use this for implementing the global dataset and how can i do this?

Thank you in advance.

hans

Sep 9 '06 #2
Am Sat, 09 Sep 2006 21:02:55 GMT schrieb Simon Tamman:

well, thank you for your answer.
I want to access a dataset threadsfae from different forms, so i though
maybe the singleton approach will help.

If the singleton nor the static is right, what would you suggest. It should
be threadsafe for sure. Btw, the dataset should be inside the application,
no external database and so on.

Thank you in advance

hans

I usually recommend the following article on the Singleton pattern.

http://www.yoda.arachsys.com/csharp/singleton.html

However I don't think you are looking for a Singleton, you just want a
static dataset, right?
So you just need to declare:

public class SomeClass
{
private static DataSet globalDataSet = new DataSet();

public static DataSet GlobalDataSet
{
// TODO: Implement locking if using multiple threads
get{return globalDataSet;}
}
}

Then you can get access to the dataset by stating:

SomeClass.Globa lDataSet

However, a static dataset sounds absolutely hideous to me and I think you
might be misunderstandin g the concepts of OOP if you are looking to use
one.
Singleton items are usually for objects or services that you only ever
want
1 of in existence, for example an object that handles the database or
possibly uses a lot of resources (i'm sure there are loads of other good
reasons too).
Datasets are usually just currency that move between architectural tiers
there is hardly ever reason to make static ones.
Could I ask what exactly do you need this static dataset for?

HTH

Simon

"Hans Greif" <un*@cubs.dewro te in message
news:4m******** ****@individual .net...
>Hallo,

hello, i try to implement a global dataset - singleton based.

On www.bakterienforum.de i found a singleton implementation:

sealed class SingletonCounte r
{
public int Counter = 0;

private SingletonCounte r(){}
public static readonly SingletonCounte r Instance = new
SingletonCount er();
}

Can i use this for implementing the global dataset and how can i do this?

Thank you in advance.

hans

Sep 9 '06 #3
I assume their is a potential need to synchronise access to the dataset as
some threads are going to change values inside it. What exactly are the
threads doing to the dataset and how up to date do they all need to be about
changes. The answers to these questions will determine the complexity of the
synchronisation code.

Ciaran O'Donnell

"Hans Greif" wrote:
Hallo,

hello, i try to implement a global dataset - singleton based.

On www.bakterienforum.de i found a singleton implementation:

sealed class SingletonCounte r
{
public int Counter = 0;

private SingletonCounte r(){}
public static readonly SingletonCounte r Instance = new
SingletonCounte r();
}

Can i use this for implementing the global dataset and how can i do this?

Thank you in advance.

hans
Sep 9 '06 #4
"Max Fox" <we*@cubs.dewro te in message
news:4m******** ****@individual .net...
Am Sat, 09 Sep 2006 21:02:55 GMT schrieb Simon Tamman:

well, thank you for your answer.
I want to access a dataset threadsfae from different forms, so i though
maybe the singleton approach will help.

If the singleton nor the static is right, what would you suggest. It
should
be threadsafe for sure. Btw, the dataset should be inside the application,
no external database and so on.
In which case, I'm a little puzzled...

You want a static dataset, but you don't populate it initially from a
database...?

So where does the data come from?

What sort of data is it?

What do you subsequently use it for?
Sep 10 '06 #5
Am Sun, 10 Sep 2006 07:54:11 +0100 schrieb Mark Rae:
"Max Fox" <we*@cubs.dewro te in message
news:4m******** ****@individual .net...
>Am Sat, 09 Sep 2006 21:02:55 GMT schrieb Simon Tamman:

well, thank you for your answer.
I want to access a dataset threadsfae from different forms, so i though
maybe the singleton approach will help.

If the singleton nor the static is right, what would you suggest. It
should
be threadsafe for sure. Btw, the dataset should be inside the
application,
no external database and so on.

In which case, I'm a little puzzled...

You want a static dataset, but you don't populate it initially from a
database...?

So where does the data come from?

What sort of data is it?

What do you subsequently use it for?
Well, i do have an initially dataset which is empty and is filled during
runtime with datas from a file. The Programm is something like a data
converter.
So what i have right now is a Dataset inside Form1 which contains the data.
But i want to access the data also outside form1, from soem different
classes. The one way is to declare the dataset as static, but that not
good. So i'm looking for an implementation of the dataset which controls
the access to it and is threadsafe.

Am i completely wrong with my thoughts?

Assuming someone wants to access the data within a dataset from different
classes, do i have to pass the dataset each time as a parameter, is that
what OOP means?

Thank you in advance

Hans
Sep 10 '06 #6
Hans,

Just open in version 2003 a component and drag a dataset on that.

In version 2005 you can click on top of Visual Studio to make your dataset.

That both creates a dataset class.

Creating a dataset static, is a nice example how in my idea static would not
be used.

However that is just my opinion,

Cor
"Hans Greif" <un*@cubs.desch reef in bericht
news:4m******** ****@individual .net...
Hallo,

hello, i try to implement a global dataset - singleton based.

On www.bakterienforum.de i found a singleton implementation:

sealed class SingletonCounte r
{
public int Counter = 0;

private SingletonCounte r(){}
public static readonly SingletonCounte r Instance = new
SingletonCounte r();
}

Can i use this for implementing the global dataset and how can i do this?

Thank you in advance.

hans

Sep 10 '06 #7
"Max Fox" <we*@cubs.dewro te in message
news:4m******** ****@individual .net...
The one way is to declare the dataset as static, but that not good.
Why not?
So i'm looking for an implementation of the dataset which controls
the access to it and is threadsafe.

Am i completely wrong with my thoughts?
It's difficult to say until you actually tell us what this dataset will
subsequently be used for.

Are you using it as the datasource for bound controls?

Why does it have to be a dataset? Why not a generic?
Assuming someone wants to access the data within a dataset from different
classes, do i have to pass the dataset each time as a parameter, is that
what OOP means?
Nothing to do with object-orient(at)ed programming per se... I have a
feeling getting yourself bogged down in nomenclature that you don't really
understand rather than taking a step back, focussing on the problem, and
coming up with a solution.

You mention that the dataset is created when Form1 is loaded - does that
mean that currently the dataset is created EVERY TIME Form1 is loaded? Is
that the problem?
Sep 10 '06 #8
Am Sat, 9 Sep 2006 22:38:38 +0200 schrieb Hans Greif:
Hallo,

hello, i try to implement a global dataset - singleton based.

On www.bakterienforum.de i found a singleton implementation:

sealed class SingletonCounte r
{
public int Counter = 0;

private SingletonCounte r(){}
public static readonly SingletonCounte r Instance = new
SingletonCounte r();
}

Can i use this for implementing the global dataset and how can i do this?

Thank you in advance.

hans
Well, i got it. thank you
Sep 11 '06 #9

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

Similar topics

11
2701
by: mrbog | last post by:
I have an array/hash that stores path information for my app. As in, what directory this is in, what directory that's in, what the name of the site is, what the products are called, etc. It's called $glb. So, every function so far looks like this: function something() { global $glb; }
1
1830
by: Chris Stromberger | last post by:
This doesn't seem like it should behave as it does without using "global d" in mod(). d = {} def mod(): d = 3 mod() print d
7
2689
by: Lyn | last post by:
Hi and Season's Greetings to all. I have a question regarding the use of a qualifier word "Global". I cannot find any reference to this in Access help, nor in books or on the Internet. "Global" seems to be recognised by Access in at least three cases:- 1) "Global Const". Recently someone in this group helped me resolve a problem, and it involved the use of a Global Const. By Googling "Global Const", I got plenty of hits -- but they...
5
3492
by: j | last post by:
Anyone here feel that "global variables" is misleading for variables whose scope is file scope? "global" seems to imply global visibility, while this isn't true for variables whose scope is file scope. If you have a variable whose scope is file scope in another translation unit, you have to provide a local declaration to access that variable from the other translation unit. Also, I don't see "global variable" used once in the standard....
5
1846
by: Pawel Janik | last post by:
Hello. I'd like to create utility, that writes something to a file, but this utility shoud be easy to access from several different applications. Because this utility have to open a file, it shoud do this only once (there is one class instance, but every application has a acces to it). What technology use here? How to do this? Pawel Janik
9
2491
by: Javaman59 | last post by:
I saw in a recent post the :: operator used to reach the global namespace, as in global::MyNamespace I hadn't seen this before, so looked it up in MSDN, which explained it nicely. My question is, do "global" and "::" always go together? Is there any other use for these operators, than as a pair? TIA,
2
3709
by: Steve | last post by:
I am new to this newsgroup & to .NET in general. I have been playing around with Visual Studio .NET, building and rendering web pages using VB "code behind" files. My problem / question is; How do I ensure that changes made to the "Global.asax.vb" file are immediately reflected in the "Global.asax" file? After I change to the "Global.asax.vb" file, the "Global.asax" file date modified does not change and I do not see the updated values...
5
4937
by: dave | last post by:
If I have a class that hold, for instance, user settings that should be accessible to the entire program logic, what is a good paradigm to use? In C++, I would have made it a global object, protected if necessary for thread safety. In C#, of course, there are no global objects. The Program object is static, so cannot contain object instances. While I could store it in my main form pass it around, that seems cumbersome. I could do a...
4
3411
ChrisWang
by: ChrisWang | last post by:
Hi, I am having trouble understanding the use of 'global' variables I want to use a global variable with the same name as a parameter of a function. But I don't know how to use them at the same time. Here is a snippet of example code: def foo (a): global p global a p = a + 3 #here "a" will be reference to the global one a = 1
0
8969
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6751
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4570
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.