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

static consts and inheritance

Hi

I have an abstract class that contains 100% static methods and variables.

One of the member variables "string DatabaseName" needs to be overridden in
derived classes.
Am I able to keep my class as totally static and do this? If so then how
please?

(I dont want to create an instance of the derived class just to query a
const string)

thanks
Claire
Jul 14 '06 #1
4 2051
Hi,

"Chukkalove" <so*****@microsoft.comwrote in message
news:ey*************@TK2MSFTNGP05.phx.gbl...
Hi

I have an abstract class that contains 100% static methods and variables.
Why you have something like this? static could be seeing as the opposite of
abstract.
One of the member variables "string DatabaseName" needs to be overridden
in derived classes.
Am I able to keep my class as totally static and do this? If so then how
please?
Why you want to have them static in the first place?
Have you seeing the Singleton pattern? Maybe that's what you are after
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jul 14 '06 #2

Chukkalove wrote:
Hi

I have an abstract class that contains 100% static methods and variables.
In order that a class be abstract, it must have at least one abstract
member, and static members cannot be abstract, so I don't know how you
did this.
One of the member variables "string DatabaseName" needs to be overridden in
derived classes.
That makes no sense. "Override in derived classes" means polymorphism,
and polymorphism works only with class instances. Since your class is
entirely static, and therefore (presumably) you would want the
"overridden" thing to be static in the child class as well, I don't
understand what you're after.
Am I able to keep my class as totally static and do this?
Absolutely not. However, I think that the problem here is one of
terminology or design. Could you step back a few paces and describe the
effect you're trying to achieve and the problem you're trying to solve?
Maybe there's a different solution for your problem, or maybe we just
misunderstand what it is you need to do.

Jul 14 '06 #3
Bruce Wood <br*******@canada.comwrote:
Chukkalove wrote:
I have an abstract class that contains 100% static methods and variables.

In order that a class be abstract, it must have at least one abstract
member, and static members cannot be abstract, so I don't know how you
did this.
You don't have to have any abstract members to make a class abstract:

abstract class Test
{
static void Main() {}
}

compiles fine.

What doesn't make sense (amongst other things) is the idea of an
abstract *variable*. Variables can't be overridden...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 14 '06 #4
Chukkalove wrote:
I have an abstract class that contains 100% static methods and variables.

One of the member variables "string DatabaseName" needs to be overridden in
derived classes.
Am I able to keep my class as totally static and do this? If so then how
please?
abstract class StaticBase
{
public static string Name = "StaticBase";
}

abstract class StaticDerived : StaticBase
{
new public static string Name = "StaticDerived";
}
Note to other repliers: a "static" class would make more sense, in 2.0
.... except that a static class can only derive directly from object.

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Jul 14 '06 #5

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

Similar topics

10
by: porneL | last post by:
How do I use static functions/properties with inheritance? I've found it very problematic. class Foo { static function A() {/* ??? */::B(); } static function B() {echo 'Foo';} }; class...
4
by: cppsks | last post by:
"Defining static const variables inside the class is not universally supported yet, so for now I guess you'll have to move the definition out of the body of the class. No, static const inside...
4
by: trying_to_learn | last post by:
I'm learning consts in C++ and the book says that u have to initialize non-static consts inside the constructor initializer list, however "const string* stack" isn't initialized in the constructor...
19
by: cody | last post by:
Iam wondering what the benefit of using const over static readonly is. static readonly is a runtime constant and can be set once in the initializer or the static ctor, whereas const is suffering...
8
by: Fernando Lopes | last post by:
Hi there! Someone has some code sample about when is recommend use a statis method? I know this methos don't want to be initialized and all but I want to know when I need to use it. Tks....
3
by: dj | last post by:
Perhaps this question should be in the standard c newsgroup, but i hope somebody answers it here. Anyway, I came across this situation in an otherwise c++ code. I need a struct that works like...
5
by: Sek | last post by:
hi folks, i have a bunch of strings used in my code in many places. these strings reside inside a instantiable class. so, i want to replace these with constant/static variable to control the...
2
by: Tim Van Wassenhove | last post by:
Hello, When i read the CLI spec, 8.10.2 Method inheritance i read the following: "A derived object type inherits all of the instance and virtual methods of its base object type. It does not...
1
by: rmdeboer82 | last post by:
I've read this thread (couldn't do a post): http://www.thescripts.com/forum/thread653679.html How is this called: CClass SomeInstance Is it a definition? I assume it is because memory is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.