Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Enumerator Class help

Enumerator Class help

Scheduled Pinned Locked Moved Visual Basic
csharphelptutorialquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    barney_1972
    wrote on last edited by
    #1

    I want to create a class to hold the many enums i have created, instead of having them in various applications. I have need where somewhere where the class contents can be accessed without instantiating the class, for example. Instead of.... Dim EnumObject as New EnumeratorClass Dim Integer as int32 Integer = EnumObject.FileActionEnum.Open I want to do......... Imports SomeNamespace.EnumeratorClass (or something similar) Dim Integer as Int32 = EnumeratorClass.FileActionEnum.Open Can anybody give me a nudge in the right direction? (Yes i am new to VB.NET) Thanks

    D G 2 Replies Last reply
    0
    • B barney_1972

      I want to create a class to hold the many enums i have created, instead of having them in various applications. I have need where somewhere where the class contents can be accessed without instantiating the class, for example. Instead of.... Dim EnumObject as New EnumeratorClass Dim Integer as int32 Integer = EnumObject.FileActionEnum.Open I want to do......... Imports SomeNamespace.EnumeratorClass (or something similar) Dim Integer as Int32 = EnumeratorClass.FileActionEnum.Open Can anybody give me a nudge in the right direction? (Yes i am new to VB.NET) Thanks

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      It's a bad idea to put all of your enums into a single class. They belong with the class(es) that's going to use them. That's where you building your own class library comes in.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      1 Reply Last reply
      0
      • B barney_1972

        I want to create a class to hold the many enums i have created, instead of having them in various applications. I have need where somewhere where the class contents can be accessed without instantiating the class, for example. Instead of.... Dim EnumObject as New EnumeratorClass Dim Integer as int32 Integer = EnumObject.FileActionEnum.Open I want to do......... Imports SomeNamespace.EnumeratorClass (or something similar) Dim Integer as Int32 = EnumeratorClass.FileActionEnum.Open Can anybody give me a nudge in the right direction? (Yes i am new to VB.NET) Thanks

        G Offline
        G Offline
        GuyThiebaut
        wrote on last edited by
        #3

        I agree with Dave. It is well worth reading up on OOP to get at least an idea of how classes etc work. It sounds like you are using a more procedural view point where macros, functions, constants etc are stored in a single place. I mention this because coming from procedural languages myself I have had to shift my viewpoint - which can feel like parking an oil tanker in a space barely the size of a small car. What I would suggest as a starter is to look at the wiki article on polymorphism - in fact here is a link Click Me. Guy

        You always pass failure on the way to success.
        B 1 Reply Last reply
        0
        • G GuyThiebaut

          I agree with Dave. It is well worth reading up on OOP to get at least an idea of how classes etc work. It sounds like you are using a more procedural view point where macros, functions, constants etc are stored in a single place. I mention this because coming from procedural languages myself I have had to shift my viewpoint - which can feel like parking an oil tanker in a space barely the size of a small car. What I would suggest as a starter is to look at the wiki article on polymorphism - in fact here is a link Click Me. Guy

          You always pass failure on the way to success.
          B Offline
          B Offline
          barney_1972
          wrote on last edited by
          #4

          Thanks for the reponse. I had already created the class but in light of your reponses i think i'll dispose of it and follow a better practice after reading up a little. Cheers

          B 1 Reply Last reply
          0
          • B barney_1972

            Thanks for the reponse. I had already created the class but in light of your reponses i think i'll dispose of it and follow a better practice after reading up a little. Cheers

            B Offline
            B Offline
            barney_1972
            wrote on last edited by
            #5

            I do have a reasonable knowledge of OOP concepts and can understand why to put the enums into their respective classes, however i am a bit confused over the mention of polymorphism. I have read the link on Wiki. Can you elaborate further why i need to undertand polymorphism in this case for moving the enums into their own classes? Thanks

            G 1 Reply Last reply
            0
            • B barney_1972

              I do have a reasonable knowledge of OOP concepts and can understand why to put the enums into their respective classes, however i am a bit confused over the mention of polymorphism. I have read the link on Wiki. Can you elaborate further why i need to undertand polymorphism in this case for moving the enums into their own classes? Thanks

              G Offline
              G Offline
              GuyThiebaut
              wrote on last edited by
              #6

              Hi, Polymorphism is a concept in OOP where the same methods, properties etc can exist accross different objects and in essence behave differently. For instance two classes called Aircraft and F1Car may have a method called Increase Throttle. The method for aircraft would increase the flow of air over the wings and cause lift whereas on the F1Car increasing the throttle would in effect cause the opposite to lift. So you can have a method called Increase Throttle that exists across multiple objects and which has a different behaviour. When it comes to programming you could even inherit the Aircraft methods, if you really wanted to, for the F1Car and override Increase Throttle to make it decrease lift. The beauty of this is that, for instance with enums, you can declare the same methods or properties across multiple classes and they will behave accordingly - so no need to declare them once only and if you need a similar method for another class create something with a slightly different name (which is what you have do do in the area of procedural programming). I hope this explains why understanding polymorphism helps. Regards Guy

              You always pass failure on the way to success.
              B 1 Reply Last reply
              0
              • G GuyThiebaut

                Hi, Polymorphism is a concept in OOP where the same methods, properties etc can exist accross different objects and in essence behave differently. For instance two classes called Aircraft and F1Car may have a method called Increase Throttle. The method for aircraft would increase the flow of air over the wings and cause lift whereas on the F1Car increasing the throttle would in effect cause the opposite to lift. So you can have a method called Increase Throttle that exists across multiple objects and which has a different behaviour. When it comes to programming you could even inherit the Aircraft methods, if you really wanted to, for the F1Car and override Increase Throttle to make it decrease lift. The beauty of this is that, for instance with enums, you can declare the same methods or properties across multiple classes and they will behave accordingly - so no need to declare them once only and if you need a similar method for another class create something with a slightly different name (which is what you have do do in the area of procedural programming). I hope this explains why understanding polymorphism helps. Regards Guy

                You always pass failure on the way to success.
                B Offline
                B Offline
                barney_1972
                wrote on last edited by
                #7

                I understand Polymorphism better than before because of your explanation, thanks. I am still confused how this applies to my Enums though. Do you have an exact example of how this would apply using enums? Thanks Ps:- To be honest what i was trying to do in the first place was probably bad practise, trying to put enums all in one place. I think as mentioned by someone ealrier they should be contained in each class.

                G 1 Reply Last reply
                0
                • B barney_1972

                  I understand Polymorphism better than before because of your explanation, thanks. I am still confused how this applies to my Enums though. Do you have an exact example of how this would apply using enums? Thanks Ps:- To be honest what i was trying to do in the first place was probably bad practise, trying to put enums all in one place. I think as mentioned by someone ealrier they should be contained in each class.

                  G Offline
                  G Offline
                  GuyThiebaut
                  wrote on last edited by
                  #8

                  Lets say you have an enum called SpeedWarning that applies to Aircraft and F1: The Aircraft enums may be as follows SpeedWarning: TooSlowStall = 120 TooFastManeuver = 350 Whereas the F1 car may have SpeedWarning: TooFastDryCorner = 150 TooFastWetCorner = 80 So both Aircraft and F1 car have SpeedWarning as an Enum however they both have different contents and values. So in this case you basically want to represent different applications of the enum SpeedWarning depending on the class they are associated with(Aircraft or F1). If SpeedWarning was defined as an enum in one place you would lose the polymorphism properties of OOP as you would have to create something akin to SpeedWarningAircraft and SpeedWarningF1 enums. Regards Guy

                  You always pass failure on the way to success.
                  B 1 Reply Last reply
                  0
                  • G GuyThiebaut

                    Lets say you have an enum called SpeedWarning that applies to Aircraft and F1: The Aircraft enums may be as follows SpeedWarning: TooSlowStall = 120 TooFastManeuver = 350 Whereas the F1 car may have SpeedWarning: TooFastDryCorner = 150 TooFastWetCorner = 80 So both Aircraft and F1 car have SpeedWarning as an Enum however they both have different contents and values. So in this case you basically want to represent different applications of the enum SpeedWarning depending on the class they are associated with(Aircraft or F1). If SpeedWarning was defined as an enum in one place you would lose the polymorphism properties of OOP as you would have to create something akin to SpeedWarningAircraft and SpeedWarningF1 enums. Regards Guy

                    You always pass failure on the way to success.
                    B Offline
                    B Offline
                    barney_1972
                    wrote on last edited by
                    #9

                    Guy, Thanks alot - just needed a good example - could'nt see the Forest because the trees were in the way!!:-D Thanks

                    G 1 Reply Last reply
                    0
                    • B barney_1972

                      Guy, Thanks alot - just needed a good example - could'nt see the Forest because the trees were in the way!!:-D Thanks

                      G Offline
                      G Offline
                      GuyThiebaut
                      wrote on last edited by
                      #10

                      No probs, I'm glad it helps :). Regards Guy

                      You always pass failure on the way to success.
                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups