473,473 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using singleton class instance in another class

Hi, I got a singleton class. Then in another class (CA), i would declare a
variable with this singleton class and get a reference to it. I would have
another class (IA1) that would inherit from CA and I would want to allow IA1
to access the singleton class. My question is is it better to declare the
singleton class as private or protected in CA? Or shall I let IA1 to get a
reference to the singleton by itself?

Thanks.
Eugene
Nov 17 '05 #1
2 1776
Hi Eugene,
make the variable protected so that the base and derived class use the
same member variable to reference the Singleton. One benefit of inheritance
is to allow code reuse from the base class.

Mark R Dawson
http://www.markdawson.org
"Eugene" wrote:
Hi, I got a singleton class. Then in another class (CA), i would declare a
variable with this singleton class and get a reference to it. I would have
another class (IA1) that would inherit from CA and I would want to allow IA1
to access the singleton class. My question is is it better to declare the
singleton class as private or protected in CA? Or shall I let IA1 to get a
reference to the singleton by itself?

Thanks.
Eugene

Nov 17 '05 #2
Mark R. Dawson <Ma*********@discussions.microsoft.com> wrote:
make the variable protected so that the base and derived class use the
same member variable to reference the Singleton. One benefit of inheritance
is to allow code reuse from the base class.


Alternatively (and preferrably, IMO) provide a protected *property*
rather than a protected variable. If you use the property everywhere in
both classes, that gives you more flexibility if you later change from
the singleton to a factory, for instance.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3

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

Similar topics

2
by: Sean Dettrick | last post by:
Hi, apologies for yet another Singleton posting. From reading around previous postings etc, I've cobbled together two Singleton template definitions - one that returns a reference, and one that...
1
by: Jim Strathmeyer | last post by:
So I'm trying to implement a singleton template class, but I'm getting a confusing 'undefined reference' when it tries to link. Here's the code and g++'s output. Any help? // singleton.h ...
2
by: davidw | last post by:
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...
9
by: Marcel Hug | last post by:
Hallo NG ! I Have a little question about inheritance of a singleton class. In my application i have a Database-Connection Lib, in which I would ¨like to connect different databases of the same...
2
by: Tim | last post by:
How can I expose a Singleton C# class to COM? I have implemented the singleton pattern for the C# class. The 'constructor' of the class is protected. Now, I want to expose this class to a VB6...
7
by: John A Grandy | last post by:
For a singleton class utilizes by ASP.NET 2.0 page processing: When initial instantiation is performed during the initial call to the retrieve instance method (let's call the method...
7
by: ThunderMusic | last post by:
Hi, I have a problem regarding singletons in C#. What I would like to do is the following ClassA is a singleton ClassB inherits from ClassA and is also a Singleton there cannot and instance of...
5
by: Damien | last post by:
Hi all, I'm using a pretty standard C++ Singleton class, as below: template <typename T> class Singleton { public: static T* Instance() {
10
by: =?Utf-8?B?ZGF2ZWJ5dGhlc2Vh?= | last post by:
Hi, I have created a Singleton class to provide some database functionality in my mobile application. I have a public class called Utility which performs various operations on data. Is it ok 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...
1
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.