473,395 Members | 1,774 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,395 software developers and data experts.

question on instances

Hi, I am wondering if there is a way to create a class where only one
predefined instance is allowed. I am just trying to find a way to create a
global variable with its own member functions whhich would be accessible by
all other classes. I could just follow the normal class thing but I'm
wondering if there is a better way to do it.thanks .
Jul 22 '05 #1
4 1000
Alan Lee wrote:
Hi, I am wondering if there is a way to create a class where only one
predefined instance is allowed. I am just trying to find a way to
create a global variable with its own member functions whhich would
be accessible by all other classes. I could just follow the normal
class thing but I'm wondering if there is a better way to do
it.thanks .


Google for the "Singleton pattern", or put your data and functions into a
namespace.

- Pete
Jul 22 '05 #2
Alan Lee wrote:
Hi, I am wondering if there is a way to create a class where only one
predefined instance is allowed. I am just trying to find a way to
create a global variable with its own member functions whhich would
be accessible by all other classes. I could just follow the normal
class thing but I'm wondering if there is a better way to do
it.thanks .


Google for the "Singleton pattern", or put your data and functions into a
namespace.

- Pete
Jul 22 '05 #3

"Alan Lee" <al*****@stanford.edu> wrote in message
news:c4**********@news.Stanford.EDU...
Hi, I am wondering if there is a way to create a class where only one
predefined instance is allowed. I am just trying to find a way to create a global variable with its own member functions whhich would be accessible by all other classes. I could just follow the normal class thing but I'm
wondering if there is a better way to do it.thanks .


Search the web for the "singleton" pattern. Typically, you must make the
constructor private or protected, and then provide a static function that
users can call to get a new object. It will only allow 1 object to exist at
a time.
Jul 22 '05 #4

"Alan Lee" <al*****@stanford.edu> wrote in message
news:c4**********@news.Stanford.EDU...
Hi, I am wondering if there is a way to create a class where only one
predefined instance is allowed. I am just trying to find a way to create a global variable with its own member functions whhich would be accessible by all other classes. I could just follow the normal class thing but I'm
wondering if there is a better way to do it.thanks .


Search the web for the "singleton" pattern. Typically, you must make the
constructor private or protected, and then provide a static function that
users can call to get a new object. It will only allow 1 object to exist at
a time.
Jul 22 '05 #5

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

Similar topics

8
by: Gonçalo Rodrigues | last post by:
Hi all, I have a template class (call it Object) whose instances have a variable size part - an array of of T objects. But this variable size part is fixed at creation time so instead of...
2
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row...
1
by: Anurag | last post by:
Hi, I have 2 related questions. DB2 UDB ESE v8.x (8.1 till 8.2 FP2 - all fixpaks included) on AIX 5.4.x _____________________________________________________________________________ (QUESTION 1)...
0
by: Jim Stools | last post by:
Hopefully this will make some sense.. I have a database that has around 50 tables - I thought about putting each table in a class and the data connection in a class then I could manage the (tables)...
4
by: Jim Stools | last post by:
Forget the re-post I had my clock set 12 hours earlier Hopefully this will make some sense.. I have a database that has around 50 tables - I thought about putting each table in a class and the...
7
by: scottgamble | last post by:
My company is making the switch to DB2 from Oracle. I have been working with Oracle for the last 10 years or so and still very very new to DB2. One question that has come up recently within our...
5
by: sittner | last post by:
i'm very new to python, but i have a pretty basic question: let's say i have a class, and i need to create a different number of instances (changes every time - and i can't know the number in...
18
by: Tom Cole | last post by:
I'm working on a small Ajax request library to simplify some tasks that I will be taking on shortly. For the most part everything works fine, however I seem to have some issues when running two...
0
by: Chris O | last post by:
"Larry Lowe" <llowejr@usa.netwrote in message news:ad17577.0308140714.1b14d778@posting.google.com... Hi Larry. Some responses aren't very helpful. I'll try to do a little better. The first...
5
by: jirkap | last post by:
I'm trying to understand how the prototype property works, but there is one thing I donť get: As far as I've got it, when I have one custom object with some methods and properties, all instances of...
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
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,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.