473,587 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can i have multiple base classes.

hi all,

I would like to be able to create an umbrella class for all my main global
sections but I would still like to keep them all in separate file something
like the below but I keep getting an error saying you are not allowed
Multiple base classes.
/// <summary>

/// This is the umbrella Object for loading all the Global classes at once.

/// It should only ever be used for this task.

/// </summary>

public class myGlobal : GlobalVariables , Settings , ErrorHandler ,StopWatch

{
}

Does any one know a way of doing this.

Thanks

ink


Feb 27 '07 #1
15 28333
"iKiLL" <iK***@NotMyEma il.comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
hi all,

I would like to be able to create an umbrella class for all my main global sections but I
would still like to keep them all in separate file something like the below but I keep
getting an error saying you are not allowed Multiple base classes.
/// <summary>

/// This is the umbrella Object for loading all the Global classes at once.

/// It should only ever be used for this task.

/// </summary>

public class myGlobal : GlobalVariables , Settings , ErrorHandler ,StopWatch

{
}

Does any one know a way of doing this.

Thanks

ink

..NET does not support Multiple Inheritance, so the answer is you can't derive from multiple
base classes.

Willy.

Feb 27 '07 #2
iKiLL wrote:
public class myGlobal : GlobalVariables , Settings , ErrorHandler
,StopWatch
{
}
..NET/C# does not support multiple inheritance. Anders Hejlsberg doesn't like
it :-)
Does any one know a way of doing this.
You should use "using" directives for the classes, you want to reference.

Ebbe
Feb 27 '07 #3
Thanks for your comments both of you,

Ebbe what do you mean by ("using" directives for the classes) is this a
simple work around.
i have found a complicated work around using Interfaces.

Thnaks,
ink


"Ebbe Kristensen" <eb**@ekologic. dkwrote in message
news:eL******** ******@TK2MSFTN GP05.phx.gbl...
iKiLL wrote:
>public class myGlobal : GlobalVariables , Settings , ErrorHandler
,StopWatch
{
}

.NET/C# does not support multiple inheritance. Anders Hejlsberg doesn't
like it :-)
>Does any one know a way of doing this.

You should use "using" directives for the classes, you want to reference.

Ebbe

Feb 27 '07 #4
"iKiLL" <iK***@NotMyEma il.comwrote in
news:#q******** ******@TK2MSFTN GP02.phx.gbl:
I would like to be able to create an umbrella class for all my main
global sections but I would still like to keep them all in separate
file something like the below but I keep getting an error saying you
are not allowed Multiple base classes.

/// <summary>

/// This is the umbrella Object for loading all the Global classes at
once.

/// It should only ever be used for this task.

/// </summary>

public class myGlobal : GlobalVariables , Settings , ErrorHandler
,StopWatch

{
}
Does any one know a way of doing this.
Can you have instance variables for your "global" classes in your
"umbrella" class?

Eg.
public class MyGlobal
{
private GlobalVariables globalVariables ;
private Settings settings;
private ErrorHandler errorHandler;
...
}

And of course you set the instances as appropriate, and expose them as
appropriate...

/Peter
Feb 27 '07 #5
iKiLL wrote:
Ebbe what do you mean by ("using" directives for the classes) is this
a simple work around.
i have found a complicated work around using Interfaces.
I am tempted to ask why you are asking that question? Surely you do know
what the "#using" directive does, don't you?

For example, if you insist on using global variables (you shouldn't but
that's another discussion), you collect them in a class in a .cs file and
get access to them in other files through a "#using" directive.

Ebbe
Feb 27 '07 #6
iKiLL <iK***@NotMyEma il.comwrote:
I would like to be able to create an umbrella class for all my main global
sections but I would still like to keep them all in separate file something
like the below but I keep getting an error saying you are not allowed
Multiple base classes.
Indeed you're not. However, I would question your design anyway. Does
your class really represent something which *is* a StopWatch and *is* a
Settings, and *is* an ErrorHandler? Or does it just *have* or use those
things? It sounds to me much more likely that composition is more
appropriate than inheritance here. (I would also worry about any class
called GlobalVariables , btw.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 27 '07 #7


hi all,

i am have been developing in VB6 for over 6 years.

I am having a hard time coming to grips with the development environment of
OOP.

The hole concept of not being able to access stuff that i need when i need
it with out loading up a entire class is really bugging me.

So fare in fact it is the most annoying part of this whole learning curve.

i am just trying to make development less time consuming with out effecting
the over program.

i really am open to suggestions but so fare all i have had from anyone is
[Why don't you just create the class when you need it.]

Below are a few things that i would like in my Global variables

public static string APPPATH =
System.IO.Path. GetDirectoryNam e(System.Reflec tion.Assembly.G etExecutingAsse mbly().GetName( ).CodeBase);

public string APP_PATH = APPPATH;

public string LOCAL_DB_PATH = APPPATH + @"\DB\";

public string ERROR_LOG_PATH = APPPATH + @"\Log\";

public string DIALOG_TITLE = "Mitie Cleaning";

public Boolean LOG_ERROR = false;

Now this means that ever time i want to access one of my paths i have to
Write the code to create the class before i can us my Variable and it is the
same with everything else.

if someone has a better suggestion then [just do it the long way like
everyone else] i would love to hear it.

thanks

ink


"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************** *@msnews.micros oft.com...
iKiLL <iK***@NotMyEma il.comwrote:
>I would like to be able to create an umbrella class for all my main
global
sections but I would still like to keep them all in separate file
something
like the below but I keep getting an error saying you are not allowed
Multiple base classes.

Indeed you're not. However, I would question your design anyway. Does
your class really represent something which *is* a StopWatch and *is* a
Settings, and *is* an ErrorHandler? Or does it just *have* or use those
things? It sounds to me much more likely that composition is more
appropriate than inheritance here. (I would also worry about any class
called GlobalVariables , btw.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Feb 27 '07 #8
You might want to try

public class MySettings
{
private static MySettings m_MySettings = null;
private string m_Path;

private static MySettings GetInstance()
{
if(m_MySettings = null)
{
m_MySettings = new MySettings();
m_MySettings.m_ Path =
System.IO.Path. GetDirectoryNam eSystem.Reflect ion.Assembly.Ge tExecutingAssem bly().GetName() .CodeBase);
}
return m_MySettings;
}

public static string GetLocalDbPath( )
{
MySettings mySettings = MySettings.GetI nstance();
return m_MySettings.m_ Path + @"\DB\";
}

public static string GetErrorLogPath ()
{
MySettings mySettings = MySettings.GetI nstance();
return m_MySettings.m_ Path + @"\Log\";
}
}

in your source code you can use

string errorFile = MySettings.GetE rrorLogPath() + "error.log" ;

The contents of MySettings apply to your entire application. Does this
answer your question?

Hans.
"iKiLL" wrote:
>

hi all,

i am have been developing in VB6 for over 6 years.

I am having a hard time coming to grips with the development environment of
OOP.

The hole concept of not being able to access stuff that i need when i need
it with out loading up a entire class is really bugging me.

So fare in fact it is the most annoying part of this whole learning curve.

i am just trying to make development less time consuming with out effecting
the over program.

i really am open to suggestions but so fare all i have had from anyone is
[Why don't you just create the class when you need it.]

Below are a few things that i would like in my Global variables

public static string APPPATH =
System.IO.Path. GetDirectoryNam e(System.Reflec tion.Assembly.G etExecutingAsse mbly().GetName( ).CodeBase);

public string APP_PATH = APPPATH;

public string LOCAL_DB_PATH = APPPATH + @"\DB\";

public string ERROR_LOG_PATH = APPPATH + @"\Log\";

public string DIALOG_TITLE = "Mitie Cleaning";

public Boolean LOG_ERROR = false;

Now this means that ever time i want to access one of my paths i have to
Write the code to create the class before i can us my Variable and it is the
same with everything else.

if someone has a better suggestion then [just do it the long way like
everyone else] i would love to hear it.

thanks

ink


"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************** *@msnews.micros oft.com...
iKiLL <iK***@NotMyEma il.comwrote:
I would like to be able to create an umbrella class for all my main
global
sections but I would still like to keep them all in separate file
something
like the below but I keep getting an error saying you are not allowed
Multiple base classes.
Indeed you're not. However, I would question your design anyway. Does
your class really represent something which *is* a StopWatch and *is* a
Settings, and *is* an ErrorHandler? Or does it just *have* or use those
things? It sounds to me much more likely that composition is more
appropriate than inheritance here. (I would also worry about any class
called GlobalVariables , btw.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Feb 27 '07 #9
Thanks Hans,

This looks like exactly what i am after.

But i am sorry i am not sure i understand how it is working.

Is this a Singleton Design Pattern. i recognize the GetInstance() from
something i was reading earlier.

How is it that this is working with out having to write all the create
object code, And at what point is this loaded into memory and destroyed from
memory?

Thanks
ink

"Hans" <Ha**@discussio ns.microsoft.co mwrote in message
news:B2******** *************** ***********@mic rosoft.com...
You might want to try

public class MySettings
{
private static MySettings m_MySettings = null;
private string m_Path;

private static MySettings GetInstance()
{
if(m_MySettings = null)
{
m_MySettings = new MySettings();
m_MySettings.m_ Path =
System.IO.Path. GetDirectoryNam eSystem.Reflect ion.Assembly.Ge tExecutingAssem bly().GetName() .CodeBase);
}
return m_MySettings;
}

public static string GetLocalDbPath( )
{
MySettings mySettings = MySettings.GetI nstance();
return m_MySettings.m_ Path + @"\DB\";
}

public static string GetErrorLogPath ()
{
MySettings mySettings = MySettings.GetI nstance();
return m_MySettings.m_ Path + @"\Log\";
}
}

in your source code you can use

string errorFile = MySettings.GetE rrorLogPath() + "error.log" ;

The contents of MySettings apply to your entire application. Does this
answer your question?

Hans.
"iKiLL" wrote:
>>

hi all,

i am have been developing in VB6 for over 6 years.

I am having a hard time coming to grips with the development environment
of
OOP.

The hole concept of not being able to access stuff that i need when i
need
it with out loading up a entire class is really bugging me.

So fare in fact it is the most annoying part of this whole learning
curve.

i am just trying to make development less time consuming with out
effecting
the over program.

i really am open to suggestions but so fare all i have had from anyone is
[Why don't you just create the class when you need it.]

Below are a few things that i would like in my Global variables

public static string APPPATH =
System.IO.Path .GetDirectoryNa me(System.Refle ction.Assembly. GetExecutingAss embly().GetName ().CodeBase);

public string APP_PATH = APPPATH;

public string LOCAL_DB_PATH = APPPATH + @"\DB\";

public string ERROR_LOG_PATH = APPPATH + @"\Log\";

public string DIALOG_TITLE = "Mitie Cleaning";

public Boolean LOG_ERROR = false;

Now this means that ever time i want to access one of my paths i have to
Write the code to create the class before i can us my Variable and it is
the
same with everything else.

if someone has a better suggestion then [just do it the long way like
everyone else] i would love to hear it.

thanks

ink


"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******* *************** **@msnews.micro soft.com...
iKiLL <iK***@NotMyEma il.comwrote:
I would like to be able to create an umbrella class for all my main
global
sections but I would still like to keep them all in separate file
something
like the below but I keep getting an error saying you are not allowed
Multiple base classes.

Indeed you're not. However, I would question your design anyway. Does
your class really represent something which *is* a StopWatch and *is* a
Settings, and *is* an ErrorHandler? Or does it just *have* or use those
things? It sounds to me much more likely that composition is more
appropriate than inheritance here. (I would also worry about any class
called GlobalVariables , btw.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too



Feb 27 '07 #10

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

Similar topics

6
6464
by: Stuart Golodetz | last post by:
Hi, I've got a minor casting issue which I need to check about (marked // <--). I was trying to do a static_cast on it (which didn't work, though I'm not sure why this should be the case?) I also tried reinterpret_cast (which is clearly an exceedingly dodgy thing to do; it worked, but I'm not sure whether it should have worked, or whether...
6
2821
by: Paul | last post by:
In real life situation, do we ever come across a situation where we would need two base objects in an object. A snippet is worth 1000 words (: so... class Base { }; class Derived1:public Base { };
20
10055
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in advance for enlightment ... here's the snippet #!/usr/bin/python
22
23337
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete examples?
5
3437
by: Scott | last post by:
Hi All, Am I correct in assuming that there is no way to have a base pointer to an object that uses multiple inheritance? For example, class A { /* ... */ }; class B { /* ... */ };
2
1848
by: Heinz Ketchup | last post by:
Hello, I'm looking to bounce ideas off of anyone, since mainly the idea of using Multiple Virtual Inheritance seems rather nutty. I chalk it up to my lack of C++ Experience. Here is my scenario... I have 5 Derived Classes I have 3 Base Classes
3
2544
by: Jess | last post by:
Hello, I've been reading Effective C++ about multiple inheritance, but I still have a few questions. Can someone give me some help please? First, it is said that if virtual inheritance is used, then "the responsibility for initializing a virtual base is borne by the most derived class in the hierarchy". What does it mean? Initializing...
47
3989
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever support multiple inheritance. In C++ for instance I noticed that the compiler flags an error if you use the "ref" keyword on a class with multiple...
13
2481
by: stephenpas | last post by:
We are trying to monkey-patch a third-party library that mixes new and old-style classes with multiple inheritance. In so doing we have uncovered some unexpected behaviour: <quote> class Foo: pass class Bar(object): pass
2
2088
by: Immortal Nephi | last post by:
You may have heard diamond shape. You create one base class. One base class has member functions and member variables. You create two derived classes. All member functions and member variables from one base class are inherited into two derived classes. You want both derived classes to share member variables of the one base class. You...
0
7915
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...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8339
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...
1
7967
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...
0
6619
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...
0
5392
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2347
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
1
1452
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.