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

Abstract Class versus Private Constructor

I need to create a shared static field for use within a number of different
classes. Which one should I be using or are they all really the same thing?

public class Widget
{
private Widget() {}
public static string DataField = string.Empty;
}

versus

public abstract class Widget
{
public static string DataField = string.Empty;
}

versus

public abstract class Widget
{
private Widget() {}
public static string DataField = string.Empty;
}
Nov 16 '05 #1
2 6708
Do you expext this class to ever be instantiated? Is this just considered a
utility class? Normally for utility classes, I make then "sealed" and use a
"private" constructor".

"Andrew Robinson" <ne****@hotmail.com> wrote in message
news:e9*************@TK2MSFTNGP12.phx.gbl...
I need to create a shared static field for use within a number of different classes. Which one should I be using or are they all really the same thing?
public class Widget
{
private Widget() {}
public static string DataField = string.Empty;
}

versus

public abstract class Widget
{
public static string DataField = string.Empty;
}

versus

public abstract class Widget
{
private Widget() {}
public static string DataField = string.Empty;
}

Nov 16 '05 #2
The private constructor is the starndard trick. Whether you make the class
abstract or not (or even sealed) won't matter much.

In the next version (VS 2005), you can apply the static keyword at class
level. Then, you don't need this private constructor trick any more.

Bruno.

"Andrew Robinson" <ne****@hotmail.com> a écrit dans le message de news:
e9*************@TK2MSFTNGP12.phx.gbl...
I need to create a shared static field for use within a number of different
classes. Which one should I be using or are they all really the same
thing?

public class Widget
{
private Widget() {}
public static string DataField = string.Empty;
}

versus

public abstract class Widget
{
public static string DataField = string.Empty;
}

versus

public abstract class Widget
{
private Widget() {}
public static string DataField = string.Empty;
}

Nov 16 '05 #3

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

Similar topics

12
by: Daedalus.OS | last post by:
Ok first I'm pretty new to OOP, so my question may sound stupid to some of you. If the only answer you can provide is "get a book about OOP" then don't loose your time and mine cause it's already...
6
by: steve bull | last post by:
I created a usercontrol class, RGBColorSpace, which is derived from an abstract class, ColorSpace, but when I try to click on the design panel for the control I get an error message "Unable to...
7
by: erin.sebastian | last post by:
Hello Everyone, This is my first attempt at coding using an abstract class and i am getting an error i can't figure out. Here is the back ground. I have a project that contains an abstract...
11
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...
17
by: baibaichen | last post by:
i have written some code to verify how to disable slicing copy according C++ Gotchas item 30 the follow is my class hierarchy, and note that B is abstract class!! class B { public: explicit...
3
by: Gustaf | last post by:
I have a class that I need to adapt to various scenarios. Some properties and methods will be needed in every case, while other's are unique for one case. So I made a base class, and a set of other...
7
by: ankitjain.bvcoe | last post by:
Hi i have the following problem in my design :::: i want to define an abstract class LogBuffer and derive two singleton classes from it i.e AlarmBuffer and FireWallBuffer.For this my design is...
7
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears...
6
by: Nindi | last post by:
5 Files Singleton.h The Singleton Factory.h The factory creating new objects. The Base class of the hierachy stores a typelist identifying the signature of the constructors to be called...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...

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.