473,480 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Inheritage - or what??

Hi there
I have this problem - might seem stupid to you and a cause of poor design
....but nevertheless it's a problem that i'm facing:

I have 1 to X singletons witch have exactly the same code - but they are in
different namespaces as they hold some information witch belongs to this
namespace.
Anyway they are called in the intizialising of my application and thereby
instantiated - and filled with the proper information .
Now the way i do taht is exactly the same way for all my singletons - and
therby repeated code for each and every.
I would like to have a method which takes a singleton and a ...say
filename... and do the work ...but i can't figure out how to do this - i
have tried with an interface - but as we all now it don't like the keyword
static :-) .....somebody know what to do???? - should mention that i'm a
relative newbee to C#

Thanx in advance
Regards
A. Rasmussen
Nov 16 '05 #1
2 1099
Hi Arne:

If the singleton is a 'single instance of an object', you probably
wouldn't have static members on the type. Perhaps you are implementing
a static class, not a singleton?

http://msdn.microsoft.com/library/de...tondespatt.asp

--
Scott
http://www.OdeToCode.com

On Fri, 24 Sep 2004 22:35:35 +0200, "Arne Rasmussen"
<ju*******@hotmail.com> wrote:
Hi there
I have this problem - might seem stupid to you and a cause of poor design
...but nevertheless it's a problem that i'm facing:

I have 1 to X singletons witch have exactly the same code - but they are in
different namespaces as they hold some information witch belongs to this
namespace.
Anyway they are called in the intizialising of my application and thereby
instantiated - and filled with the proper information .
Now the way i do taht is exactly the same way for all my singletons - and
therby repeated code for each and every.
I would like to have a method which takes a singleton and a ...say
filename... and do the work ...but i can't figure out how to do this - i
have tried with an interface - but as we all now it don't like the keyword
static :-) .....somebody know what to do???? - should mention that i'm a
relative newbee to C#

Thanx in advance
Regards
A. Rasmussen


Nov 16 '05 #2
What i have is the following:

using System;

namespace TestAfInstance.TestClass1
{
public class Class1
{
private static Class1 instance;

private string someVariable;

public static Class1 Instance()
{
if (instance == null)
{
instance = new Class1();
}
return instance;
}

public string SomeVariable
{
get{return someVariable;}
set{someVariable = value;}
}
}
}
Now i have several of these class'es but they differ in namespace.
However i found the solution - i have a baseclass implementing the
property SomeVariable wich the singletons inherits i then do the
following to have common code

BaseClass base = <somenamespace>.instance();

and then accesing base.SomeVariable for all the namespaces

Regards
Arne Rasmussen

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

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

Similar topics

2
3047
by: thecrow | last post by:
Alright, what the hell is going on here? In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is...
220
18791
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
699
33298
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
92
6323
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
137
6914
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
12
11119
by: Dario | last post by:
The following simple program behaves differently in Windows and Linux . #include <stdexcept> #include <iostream> #include <string> using namespace std; class LogicError : public logic_error {...
125
14524
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
1098
by: mandatory | last post by:
hi, i have two classes: class A { public: virtual Push (void *p); };
5
1852
by: Summa | last post by:
Hi, Can I somehow specify that Class A can inherit from Class B *and* Class C? -- Thanks, Summa
0
7054
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
7102
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
6756
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
7003
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
5357
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,...
0
4495
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
1310
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 ...
1
570
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
199
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...

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.