473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

static classes

Hi all,
I was wondering: Why isn't it possible to write "static classes". By
this I mean a class that will _never_ get instantiated, but will always
work on and with other static members of its class.

The class would in effect behave like a "classic" win32 dll and its
exported functions, only this time referred by
<classname>.<Ex portedFunction>

I know (how) I can achieve the same results with a singleton, but why
not just mark the entire class as "static" instead of marking every
single member as static?

I'm quite new to .NET (digging, gropin and mutilating around for about 8
months now), so, my questions are:
- Is it possible?
- If not, are there better solutions to my "problem"?
- Would it any how be a nice language/platform addition?

Thanks in advance,

Willem





Nov 16 '05 #1
6 1910
Try creating your class with all static members and a private constructor.
No instanciation anymore. Just like the MessageBox class
(http://msdn.microsoft.com/library/de...-us/cpref/html
/frlrfsystemwind owsformsmessage boxclasstopic.a sp)

Telmo Sampaio

"Willem van Rumpt" <no***********@ no.thelandslide .spam.com> wrote in message
news:#p******** ******@TK2MSFTN GP11.phx.gbl...
Hi all,
I was wondering: Why isn't it possible to write "static classes". By
this I mean a class that will _never_ get instantiated, but will always
work on and with other static members of its class.

The class would in effect behave like a "classic" win32 dll and its
exported functions, only this time referred by
<classname>.<Ex portedFunction>

I know (how) I can achieve the same results with a singleton, but why
not just mark the entire class as "static" instead of marking every
single member as static?

I'm quite new to .NET (digging, gropin and mutilating around for about 8
months now), so, my questions are:
- Is it possible?
- If not, are there better solutions to my "problem"?
- Would it any how be a nice language/platform addition?

Thanks in advance,

Willem




Nov 16 '05 #2
Willem,
I understand that C# 2.0 (part of VS.NET 2005 aka Whidbey) will have static
classes.

http://lab.msdn.microsoft.com/vs2005/

http://msdn.microsoft.com/vcsharp/de...0/default.aspx

Hope this helps
Jay

"Willem van Rumpt" <no***********@ no.thelandslide .spam.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi all,
I was wondering: Why isn't it possible to write "static classes". By
this I mean a class that will _never_ get instantiated, but will always
work on and with other static members of its class.

The class would in effect behave like a "classic" win32 dll and its
exported functions, only this time referred by
<classname>.<Ex portedFunction>

I know (how) I can achieve the same results with a singleton, but why
not just mark the entire class as "static" instead of marking every
single member as static?

I'm quite new to .NET (digging, gropin and mutilating around for about 8
months now), so, my questions are:
- Is it possible?
- If not, are there better solutions to my "problem"?
- Would it any how be a nice language/platform addition?

Thanks in advance,

Willem




Nov 16 '05 #3

"Willem van Rumpt" <no***********@ no.thelandslide .spam.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi all,
I was wondering: Why isn't it possible to write "static classes". By this
I mean a class that will _never_ get instantiated, but will always work on
and with other static members of its class.


Probably because no one thought it would be as valueable as it has turned
out to be. C# 2.0 will support static classes for pretty much this reason.
You will have to mark every member as static still, but the compiler throws
an error if you don't, and it takes care of the sealing and private
constructor.

Outside of that, what you want is achievable, just mark your class as sealed
and give it a private constructor(wit h no public ones). That'll stop
initalizations.
Nov 16 '05 #4
Willem van Rumpt wrote:
Hi all,
I was wondering: Why isn't it possible to write "static classes". By
this I mean a class that will _never_ get instantiated, but will always
work on and with other static members of its class.
Excellent idea and as other posters have pointed out -- will be implemented
in 2.0

As far as why it wasn't implemented before, I think the bent was towards
classes as universals that are shared between applications -- rather than
called within a single app ( which, in practice, is actually far more
common ).

The class would in effect behave like a "classic" win32 dll and its
exported functions, only this time referred by
<classname>.<Ex portedFunction>

I know (how) I can achieve the same results with a singleton, but why
not just mark the entire class as "static" instead of marking every
single member as static?

I'm quite new to .NET (digging, gropin and mutilating around for about 8
months now), so, my questions are:
- Is it possible?
- If not, are there better solutions to my "problem"?
- Would it any how be a nice language/platform addition?

Thanks in advance,

Willem


Nov 16 '05 #5
thank you all for your replies. I'll make do with the provided
solutions, have a look at the C# 2.0 specs, and wait for Whidbey to
arrive (somewhere late autumn 2008, as I've understood ;) ).

Willem van Rumpt
Nov 16 '05 #6
Hi Willem,

If you want to start playing with it now, you can download the new Visual
Studio 2005 Express Beta 1:

http://lab.msdn.microsoft.com/express/vcsharp/

Joe
--
Joe Mayo, Author/Instructor
Need C#/.NET training?
visit www.mayosoftware.com
C# Tutorial - www.csharp-station.com
"Willem van Rumpt" <no***********@ no.thelandslide .spam.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
thank you all for your replies. I'll make do with the provided
solutions, have a look at the C# 2.0 specs, and wait for Whidbey to
arrive (somewhere late autumn 2008, as I've understood ;) ).

Willem van Rumpt

Nov 16 '05 #7

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

Similar topics

5
2063
by: Thomas Matthews | last post by:
Hi, I have three classes: Category Author Publisher Each of these classes stores its information into a database table of <ID, text>. (They are fields that have a foreign key.) There is only one table for each instance of these classes (IOW,
9
2664
by: Laban | last post by:
Hi, I find myself using static methods more than I probably should, so I am looking for some advice on a better approach. For example, I am writing an app that involves quite a bit of database operations on purchase orders and inventory. I have created a PurchaseOrder class and Inventory class to encapsulate operations like creating POs, finding items, etc. These two classes are used extensively from different parts of the app.
4
10766
by: Bryan Green | last post by:
So I'm working on a project for a C# class I'm taking, where I need to keep some running totals via static variables. I need three classes for three different types of objects. The base class and inherited classes are all identical. I need to refer to the static variables in each class, and each must maintain its own values for each static variable. Now: when I inherit my base classes, the static variables in all my classes contain...
11
3846
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you experts. I would like to produce Javascript classes that can be "subclassed" with certain behaviors defined at subclass time. There are plenty of ways to do this through prototyping and other techniques, but these behaviors need to be static and...
6
1776
by: MSDNAndi | last post by:
Hi, I have a baseclass (non-static) with some static and some non-static methods/fields/properties. In the baseclass in one of the static methods I need to do something like " somelogic .... CallToStaticMethod();
4
2994
by: DBC User | last post by:
I have a class with bunch of static methods. I could regourp all the static methods into seperate 3 or 4 classes. I was thinking about using Singlton pattern for all these 4 classes so that it behaves like static still class. But my concern is, when going from static to singlton, I need to add one more line to make sure the class is instantiated. Am I going in right direction? Thanks for the help.
6
4221
by: GroupReader | last post by:
In my app, I have two very similar static classes. After long thought, I've decided *yes - keep them static*. - Sometimes I will want to use Static Class A, and somtimes I will want to use Static Class B, depending on the situation. - The interfaces (are interfaces allowed on static classes?) are almost identical. What's the best way in code to create some sort of "factory" that will
2
1567
by: mark4asp | last post by:
Q: Initialising and updating a class with only static members & database dependency I have a class with the following members: public static List<ACISACIS_List; static AssetClass() { // blah } public static ACIS Get_ACIS(string sACISCode) { // blah }
17
8384
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline the function if possible" (because if the compiler has the function definition available at an instantiation point, it will estimate whether to inline it or not, and do so if it estimates it would be beneficial, completely regardless of whether...
9
267
by: puzzlecracker | last post by:
It looks like static classes can have non-static member classes -- does it make sense what I just wrote? If not, let me illustrate it: public static class Foo{ private struct Bar{ } }
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10152
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8974
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
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 we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.