473,385 Members | 2,013 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.

"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 SingletonCounter
{
public int Counter = 0;

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

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 8008
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.GlobalDataSet

However, a static dataset sounds absolutely hideous to me and I think you
might be misunderstanding 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.dewrote 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 SingletonCounter
{
public int Counter = 0;

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

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.GlobalDataSet

However, a static dataset sounds absolutely hideous to me and I think you
might be misunderstanding 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.dewrote 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 SingletonCounter
{
public int Counter = 0;

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

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 SingletonCounter
{
public int Counter = 0;

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

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.dewrote 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.dewrote 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.deschreef 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 SingletonCounter
{
public int Counter = 0;

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

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.dewrote 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 SingletonCounter
{
public int Counter = 0;

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

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
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...
1
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
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"...
5
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...
5
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...
9
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...
2
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...
5
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,...
4
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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...
0
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...

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.