How can i have multiple base classes.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iKiLL

    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




  • Willy Denoyette [MVP]

    #2
    Re: How can i have multiple base classes.

    "iKiLL" <iKill@NotMyEma il.comwrote in message
    news:%23q174plW HHA.1200@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.



    Comment

    • Ebbe Kristensen

      #3
      Re: How can i have multiple base classes.

      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


      Comment

      • iKiLL

        #4
        Re: How can i have multiple base classes.

        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" <ebbe@ekologic. dkwrote in message
        news:eLOvlxlWHH A.1396@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
        >

        Comment

        • Peter K

          #5
          Re: How can i have multiple base classes.

          "iKiLL" <iKill@NotMyEma il.comwrote in
          news:#q174plWHH A.1200@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

          Comment

          • Ebbe Kristensen

            #6
            Re: How can i have multiple base classes.

            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


            Comment

            • Jon Skeet [C# MVP]

              #7
              Re: How can i have multiple base classes.

              iKiLL <iKill@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 - <skeet@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

              Comment

              • iKiLL

                #8
                Re: How can i have multiple base classes.



                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]" <skeet@pobox.co mwrote in message
                news:MPG.204e21 d7af88f20d98d8d 9@msnews.micros oft.com...
                iKiLL <iKill@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 - <skeet@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

                Comment

                • =?Utf-8?B?SGFucw==?=

                  #9
                  Re: How can i have multiple base classes.

                  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]" <skeet@pobox.co mwrote in message
                  news:MPG.204e21 d7af88f20d98d8d 9@msnews.micros oft.com...
                  iKiLL <iKill@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 - <skeet@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
                  >
                  >
                  >

                  Comment

                  • iKiLL

                    #10
                    Re: How can i have multiple base classes.

                    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" <Hans@discussio ns.microsoft.co mwrote in message
                    news:B2064565-E04A-45AC-83D3-D1C44B92E64A@mi crosoft.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]" <skeet@pobox.co mwrote in message
                    >news:MPG.204e2 1d7af88f20d98d8 d9@msnews.micro soft.com...
                    iKiLL <iKill@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 - <skeet@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
                    >>
                    >>
                    >>

                    Comment

                    • Jon Skeet [C# MVP]

                      #11
                      Re: How can i have multiple base classes.

                      iKiLL <iKill@NotMyEma il.comwrote:
                      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.
                      That's not really the best way of going - if you try to shoehorn an OO
                      environment into your non-OO mindset, you're going to be fighting it
                      every step of the way.
                      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;
                      Firstly, look into the .NET naming conventions - these should be things
                      like ApplicationPath (although look at Application.Exe cutablePath for
                      an easier way of doing this), LocalDatabasePa th, ErrorLogPath,
                      DialogTitle and LogError.
                      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.
                      No you don't. Either you could use the Singleton pattern, or just make
                      the above into static variables (or preferably properties).

                      It's well worth reading a book or tutorial on OO before going too much
                      further. I'm not saying that to be unkind - I just know how easy it is
                      to carry practices from one environment into another where they're not
                      appropriate.

                      --
                      Jon Skeet - <skeet@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

                      Comment

                      • iKiLL

                        #12
                        Re: How can i have multiple base classes.



                        Ok i think i have figured it out



                        The object creates it self the first time any of its properties are called
                        and then tests the internal object each time to make sure it only loads
                        itself up once into memory.



                        And then I assume that it will remain in memory till the application shuts
                        down.



                        But how is the Properties exposed the very first time[string errorFile =
                        MySettings.GetE rrorLogPath() + "error.log" ;], if the object is not in memory
                        yet.

                        Is this some sort of rule that is just allowed. or am i missing something.



                        Thanks,

                        ink











                        "iKiLL" <iKill@NotMyEma il.comwrote in message
                        news:OUAdcomWHH A.5008@TK2MSFTN GP05.phx.gbl...
                        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" <Hans@discussio ns.microsoft.co mwrote in message
                        news:B2064565-E04A-45AC-83D3-D1C44B92E64A@mi crosoft.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 .GetDirectoryNa meSystem.Reflec tion.Assembly.G etExecutingAsse mbly().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.Pat h.GetDirectoryN ame(System.Refl ection.Assembly .GetExecutingAs sembly().GetNam e().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]" <skeet@pobox.co mwrote in message
                        >>news:MPG.204e 21d7af88f20d98d 8d9@msnews.micr osoft.com...
                        >iKiLL <iKill@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 - <skeet@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
                        >>>
                        >>>
                        >>>
                        >
                        >

                        Comment

                        • Ebbe Kristensen

                          #13
                          Re: How can i have multiple base classes.

                          iKiLL wrote:
                          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.
                          It is indeed. A singleton works as follows:

                          first, the class contains a class variable, i.e. a variable tied to the
                          class instead of to an instance of the class. This is the "private static
                          MySettings m_MySettings = null;" at the start of the class.

                          The only way to get the access to an instance of this class is by calling
                          the GetInstance() method. This method checks to see if an instance has been
                          created. If not, it creates one and stores a reference to it in the
                          'm_MySettings' variable and initialises the other variables in the object.
                          Whether or not a new instance is created, a reference to it is returned to
                          the caller, who can then access the public interfaces to it - and only
                          those. In this case there are a couple of GetXxxx methods whereas the actual
                          values are not accessible. This design ensures that you cannot accidentally
                          change the settings.

                          Using a singleton ensures that you always refer to the same object. Without
                          it you might end up with two different object of the same class and a bunch
                          of hard-to-find errors.
                          How is it that this is working with out having to write all the create
                          object code,
                          Hmm, seems that Hans forgot a:

                          private void MySettings() {};
                          And at what point is this loaded into memory and destroyed from memory?
                          It is loaded on first access to it. Unload is something you don't need to
                          think about, .NET does it for you when the object is no longer needed. This
                          is what they call garbage collection.

                          Ebbe


                          Comment

                          • =?ISO-8859-1?Q?G=F6ran_Andersson?=

                            #14
                            Re: How can i have multiple base classes.

                            iKiLL wrote:
                            But how is the Properties exposed the very first time[string errorFile =
                            MySettings.GetE rrorLogPath() + "error.log" ;], if the object is not in memory
                            yet.
                            >
                            Is this some sort of rule that is just allowed. or am i missing something.
                            They are static. That means that they are accessed through the class,
                            not through an instance of the class.

                            --
                            Göran Andersson
                            _____
                            Göran Anderssons privata hemsida.

                            Comment

                            • Paul Werkowitz

                              #15
                              Re: How can i have multiple base classes.

                              Am Tue, 27 Feb 2007 11:09:45 -0000 schrieb Jon Skeet [C# MVP]:
                              >
                              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.)
                              I agree here, but pls look at the following:
                              I have derivations of TextBox, Combobox, Checkbox, Label, TreeView and some
                              more. They all implement the same additional stuff - connection to a member
                              of a business object. For each of the controls, this is about 100 lines of
                              code, of which 80-95% are the same for each control. Due to the lack of MI,
                              I can't factor it out.

                              It is simply annoying to have to write things like

                              //-----------------------------------------------------------------
                              // boBindName
                              //
                              [
                              Bindable (true)
                              , Category ("QFC")
                              , Description ("Feld/Property, an das gebunden werden soll")
                              ]
                              public string boBindName
                              {
                              get { return mBoBindName; }
                              set { mBoBindName = value; }
                              }

                              over and over again and identical in all controls. This is stupid, and
                              exactly this is one of the things MI was invented for.

                              My 2 cents..
                              Paule

                              Comment

                              Working...