By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,007 Members | 1,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,007 IT Pros & Developers. It's quick & easy.

static consts and inheritance

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.