Can a static class inherit from something?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wagger
    New Member
    • Feb 2008
    • 3

    Can a static class inherit from something?

    Hi!
    I am creating a set of static classes, one class for each "case" I have. The class should do and perform certain things, and the different static classes are doing different things.

    However, in each static class there must be 3 properties (id, name and description) and I thought I just create an abstract class and define them there and let all the static classes (ie the cases) inherit from that and thus forcing them to implement the properties.

    This, however, cannot be done.

    Question is - is there a way for a static class to inherit from another class? I need to defined properties that they MUST implement.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by wagger
    Hi!
    I am creating a set of static classes, one class for each "case" I have. The class should do and perform certain things, and the different static classes are doing different things.

    However, in each static class there must be 3 properties (id, name and description) and I thought I just create an abstract class and define them there and let all the static classes (ie the cases) inherit from that and thus forcing them to implement the properties.

    This, however, cannot be done.

    Question is - is there a way for a static class to inherit from another class? I need to defined properties that they MUST implement.
    Why are you making the classes static? What problem are you modelling/trying to solve?
    This is not the way to design programs. You don't decide before hand that you are going to have static classes and then try to fit the problem to your static classes. Rather the problem decides which classes are needed and of which type.

    Comment

    • wagger
      New Member
      • Feb 2008
      • 3

      #3
      Thanks for the no-answer...

      Comment

      • shweta123
        Recognized Expert Contributor
        • Nov 2006
        • 692

        #4
        Hi,

        Please read this article regarding your doubt.

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by wagger
          Thanks for the no-answer...
          I thought the reason you posted was because you wanted to learn. Many .NETters actually make the same mistake that you made above in your design. You'll find out soon enough about the importance of program design.

          Comment

          • wagger
            New Member
            • Feb 2008
            • 3

            #6
            Hi,
            I'm not really new to it... Written a system with a lot of different programs, communication over TCP/IP/radio, network programming etc etc.

            The thing is that when someone asks a specific question, like the one I asked, a person is rarely interested in smart remarks. They just want to know the answer to the question.

            Usually, not always, but usually its just annoying when someone tries to lecture you in this or that "school-book version" on program design or whatever.

            Anyways, question has been answered I think =)

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by wagger
              Hi,
              I'm not really new to it... Written a system with a lot of different programs, communication over TCP/IP/radio, network programming etc etc.

              The thing is that when someone asks a specific question, like the one I asked, a person is rarely interested in smart remarks. They just want to know the answer to the question.

              Usually, not always, but usually its just annoying when someone tries to lecture you in this or that "school-book version" on program design or whatever.

              Anyways, question has been answered I think =)
              There's lots of questions asked here where people get problems because they are using the wrong approach altogether. If you've written lots of software then you should agree with me that program design is very important.
              Coming back to your question, static members belong to a class and so cannot be inherited. Static classes can only derive from the object class. So the answer would be yes they can inherit something but only from the object class.

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Originally posted by My VisualStudio
                Error 1 Static class 'InternalProduc tion.dummyclass ' cannot derive from type 'System.Windows .Forms.Form'. Static classes must derive from object.
                Seems like another question that could have been answered with 4seconds of trying it out.

                Comment

                Working...