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

How to design/write GlobalConfig class that can be inherited?

Hi.

I need to create a GlobalConfig class. But I want to derive from it in another class.

Here's an example:

Expand|Select|Wrap|Line Numbers
  1. public class BaseConfig {
  2.  public string GlobalPath {get; set;}
  3. }
  4.  
  5. public class ConfigA :  BaseConfig  {
  6.  public string pathA {get; set;}
  7. }
  8.  
  9. public class ConfigB :  ConfigA  {
  10.  public string pathB {get; set;}
  11. }
The idea behind is that I don't want to write the code multiple times and what's more important
in class ConfigA I want to set GlobalPath and have access to it in ConfigB.

In other word I want class ConfigB to have a property GlobalPath which was set in class ConfigA.

To clarify I want to have only one object of Config in memory.

When I set BaseConf.GlobalPath to 'A', I want to access it from ConfigB.GlobalPath and also get 'A'.

I always design GlobalConfig as a static class, but static classes can't be inherited.
So I tried to implement Singleton Pattern, but ConfigA can't find constructor of class BaseConfig because
it's private.

I'll appreciate all help and suggestions.
Thank you.
Jan 31 '13 #1
1 1372
Joseph Martell
198 Expert 128KB
Instead of using the automatically generated property syntax, try creating a property in your ConfigBase class that refers to a private static member. There is no rule that says you have to refer to an instance member when using an instance property.

Something along the lines of this:

Expand|Select|Wrap|Line Numbers
  1.     public abstract class TestBase
  2.     {
  3.         private static string _path;
  4.  
  5.         public string Path
  6.         {
  7.             get { return _path; }
  8.             set { _path = value; }
  9.         }
  10.     }
  11.  
  12.     public class TestA
  13.         : TestBase
  14.     { }
  15.  
  16.     public class TestB
  17.         : TestBase
  18.     { }
  19.  
Now the path should be the same between all instances of TestA and TestB and because TestBase is declared as abstract it cannot be instantiated directly.
Feb 8 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Hartmut Dippon | last post by:
Hello, does anybody know how I can access and modify properties of my frameset within my code behind class, or is that not possible at all? I tried to find anything in the internet about this...
1
by: AP | last post by:
Hi, I am trying to inherit from a base class and use that as my code behind class for various forms that have common functionality. The problem is that when I try to view the form in the form...
2
by: jm | last post by:
I am still migrating from old ASP to ASP.NET with VB.NET. I created an app as a single file type application and later found out about Visual Studio and code behind class files. Is that the...
1
by: Dhiman | last post by:
Here is the problem. I have a parant class where I have declared couple of variables for user control that I will be using in the web pages. (ParentPage.vb) This class is inherited by the code...
5
by: GaryB | last post by:
The following line of code works fine in my code-behind file for an aspx page: Dim HeadingRow As DataRow = dsGridReport.Tables(0).NewRow() But when I transport that same code to a class and...
3
by: Biff | last post by:
Hello, I am bringing up an iFrame with a calendar control in it in coordination with a text box that holds a date field. In my code behind class I add a method call to the text box's OnFocus...
4
by: Ian Meakin | last post by:
I have a page called admin.aspx and it uses admin.aspx.cs as it's code behind file. When developing the application on my localhost using VS.NET i reference thsi file using...
2
by: Mahesh P | last post by:
Hi all; I am using code behind class with each aspx page; can i use multiple code behind class with a single aspx page. dont consider user controls.
0
by: TCook | last post by:
Hey All, I'm trapping a 'submit' button's 'Click' event in a VB.Net code behind class in order to loop through a 'Select' controls 'option' list as follows: For Each ThisItem In...
0
by: sonny.stevenson | last post by:
I created a global object with the following in the global.asax class <object id="mainObj" runat="server" class="global_Object.MAIN" scope="Application" /> I have been searching online for a...
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
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
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
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
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
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
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...
0
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.