PC Review


Reply
Thread Tools Rate Thread

How can i have multiple base classes.

 
 
iKiLL
Guest
Posts: n/a
 
      27th Feb 2007
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




 
Reply With Quote
 
 
 
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      27th Feb 2007
"iKiLL" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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.



 
Reply With Quote
 
Ebbe Kristensen
Guest
Posts: n/a
 
      27th Feb 2007
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


 
Reply With Quote
 
iKiLL
Guest
Posts: n/a
 
      27th Feb 2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Peter K
Guest
Posts: n/a
 
      27th Feb 2007
"iKiLL" <(E-Mail Removed)> wrote in
news:#(E-Mail Removed):

> 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
 
Reply With Quote
 
Ebbe Kristensen
Guest
Posts: n/a
 
      27th Feb 2007
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


 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      27th Feb 2007
iKiLL <(E-Mail Removed)> wrote:
> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
iKiLL
Guest
Posts: n/a
 
      27th Feb 2007


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.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> iKiLL <(E-Mail Removed)> wrote:
>> 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 - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too



 
Reply With Quote
 
=?Utf-8?B?SGFucw==?=
Guest
Posts: n/a
 
      27th Feb 2007
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.GetDirectoryNameSystem.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
}
return m_MySettings;
}

public static string GetLocalDbPath()
{
MySettings mySettings = MySettings.GetInstance();
return m_MySettings.m_Path + @"\DB\";
}

public static string GetErrorLogPath()
{
MySettings mySettings = MySettings.GetInstance();
return m_MySettings.m_Path + @"\Log\";
}
}

in your source code you can use

string errorFile = MySettings.GetErrorLogPath() + "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.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().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]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > iKiLL <(E-Mail Removed)> wrote:
> >> 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 - <(E-Mail Removed)>
> > http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> > If replying to the group, please do not mail me too

>
>
>

 
Reply With Quote
 
iKiLL
Guest
Posts: n/a
 
      27th Feb 2007
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" <(E-Mail Removed)> wrote in message
news:B2064565-E04A-45AC-83D3-(E-Mail Removed)...
> 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.GetDirectoryNameSystem.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
> }
> return m_MySettings;
> }
>
> public static string GetLocalDbPath()
> {
> MySettings mySettings = MySettings.GetInstance();
> return m_MySettings.m_Path + @"\DB\";
> }
>
> public static string GetErrorLogPath()
> {
> MySettings mySettings = MySettings.GetInstance();
> return m_MySettings.m_Path + @"\Log\";
> }
> }
>
> in your source code you can use
>
> string errorFile = MySettings.GetErrorLogPath() + "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.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().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]" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > iKiLL <(E-Mail Removed)> wrote:
>> >> 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 - <(E-Mail Removed)>
>> > http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
>> > If replying to the group, please do not mail me too

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple base classes workaround Nigil Chua Microsoft Dot NET Framework 1 26th Feb 2008 06:24 PM
Multiple base classes in .NET Larry Smith Microsoft Dot NET Framework 48 26th Jul 2007 03:42 PM
Multiple base classes in .NET Larry Smith Microsoft C# .NET 48 26th Jul 2007 03:42 PM
Multiple Base Classes in .Net Rory Becker Microsoft Dot NET Framework 9 23rd Jul 2007 07:16 PM
Multiple base classes in .NET Larry Smith Microsoft VC .NET 0 14th Jul 2007 12:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:34 PM.