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. C#
  4. Multiple Classes, same name

Multiple Classes, same name

Scheduled Pinned Locked Moved C#
csharpquestionannouncement
69 Posts 15 Posters 1 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.
  • W Wiep Corbier

    I'm a senior. This is not a problem for me. It works 100% perfect. I have solved this years ago. Trust me. Anyway, back to the topic please. But you already gave me an answer. Thanks. :thumbsup:

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

    Just because "it's worked for years", doesn't mean it was designed properly. The list of skills NEVER should have been a string holding multiple values like that. It should have been a separate table with foreign keys back to the people that have those skills. The skill is stored ONCE and can be used multiple times. This saves space in the database. It's not the language that needs to updated to support your poor skills. It's your skills that need to be updated to better support your customers.

    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
    Dave Kreskowiak

    W OriginalGriffO 2 Replies Last reply
    0
    • W Wiep Corbier

      Asking questions is a skill I will never ask a question on this platform again. Thanks for your reply. Have a nice day.

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

      Why is asking questions a skill? Because you have to think about your question before you ask it. Think about the context your question falls in. All you said was "I want this, and it's up to the experts to solve it". Well, the experts just told you your idea isn't workable at all and you just stomped off. But, actually, the idea is kind of workable, but it would involve converting C# to an interpreted language instead of compiled. It would also involve rewriting the type resolver to examine the code ahead to attempt to find the "best fit" at runtime based on insufficient information. This wouldn't even work in all cases as there isn't enough information at runtime to even "new up" an instance you haven't used yet. This would also have the effect of destroying the performance of the language because of all of the overhead of trying to guess at which type you were talking about!

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      1 Reply Last reply
      0
      • K kalberts

        Ten years from now, kids will honestly believe that Elon Musk invented the electric car, and all later (and earlier) electric cars are derived from the Tesla series.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #42

        Well they have to teach them something in school.

        N 1 Reply Last reply
        0
        • D Dave Kreskowiak

          Just because "it's worked for years", doesn't mean it was designed properly. The list of skills NEVER should have been a string holding multiple values like that. It should have been a separate table with foreign keys back to the people that have those skills. The skill is stored ONCE and can be used multiple times. This saves space in the database. It's not the language that needs to updated to support your poor skills. It's your skills that need to be updated to better support your customers.

          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
          Dave Kreskowiak

          W Offline
          W Offline
          Wiep Corbier
          wrote on last edited by
          #43

          The list of skills NEVER should have been a string holding multiple values like that. It should have been a separate table with foreign keys That was my original idea too. Very logical. I would do it also, even as a habit BUT By exeption I will explain: Take a skills list with 1000 skills. Put them in a list. Now find and skill item with the value "Skill 1" Maybe, this skill is on position 998 Do a find: it will seach at least 998 items in a list before that skill is found Do a contains on a string and there is one search. If(Skill.Contains("|Skill 1|")) than, a Yes or a No. True or False. If I'm wrong, I will redesign.

          Z K 2 Replies Last reply
          0
          • W Wiep Corbier

            Asking questions is a skill I will never ask a question on this platform again. Thanks for your reply. Have a nice day.

            Z Offline
            Z Offline
            ZurdoDev
            wrote on last edited by
            #44

            Wiep Corbier wrote:

            I will never ask a question on this platform again.

            That's not the right approach. My observation is that you had a clever idea and wanted to share. That's great and awesome and thank you for doing that. I think where this went south is that you wanted everyone else to think it was clever and no one else has. That's fine. Don't take it personal. If you think it's a great idea pursue it and prove everyone wrong. Don't run away just because no one agreed with you. Don't take these posts personal. No one is attacking you, they were just attacking the idea. But keep having ideas. That's how innovation happens.

            Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

            1 Reply Last reply
            0
            • W Wiep Corbier

              The list of skills NEVER should have been a string holding multiple values like that. It should have been a separate table with foreign keys That was my original idea too. Very logical. I would do it also, even as a habit BUT By exeption I will explain: Take a skills list with 1000 skills. Put them in a list. Now find and skill item with the value "Skill 1" Maybe, this skill is on position 998 Do a find: it will seach at least 998 items in a list before that skill is found Do a contains on a string and there is one search. If(Skill.Contains("|Skill 1|")) than, a Yes or a No. True or False. If I'm wrong, I will redesign.

              Z Offline
              Z Offline
              ZurdoDev
              wrote on last edited by
              #45

              Wiep Corbier wrote:

              Maybe, this skill is on position 998 Do a find: it will seach at least 998 items in a list before that skill is found

              Actually, that's what indexes on a database table are for. If you had a Skills table it would not have to do a table scan to find the specific skill you wanted. And it would actually be much much faster than checking all the strings to see if it contains. You would use foreign keys and it would be magnitudes faster than doing a LIKE statement.

              Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

              W OriginalGriffO 2 Replies Last reply
              0
              • W Wiep Corbier

                For the next C# version I would like the ability to have multiple classes with the same name. But, this is for POCO's What do I mean? I have an poco with the name CandidateFunction

                public class CandidateFunction
                {
                    public int CandidateFunctionId { get; set; }
                    public int CandidateId { get; set; }
                    public int FunctionId { get; set; }
                    public string Skills { get; set; }
                    public DateTime Date { get; set; }
                }
                

                As you can see, the property with the name Skills is a string. It can be a long string and it stores one or more Skills. But customers want to see Skills as a list so I have another POCO

                public class CandidateFunctionWithSkillsList
                {
                    public int CandidateFunctionId { get; set; }
                    public int CandidateId { get; set; }
                    public int FunctionId { get; set; }
                    public List Skills { get; set; }
                    public DateTime Date { get; set; }
                }
                

                It has another name. Now, I want both POCO's with the same name. I know there alternatives for what I want but I don't like them. So, when I instantiate a new CandidateFunction, I want a popup asking me which one I want to use. Will this ever happen and if not, why not?

                Z Offline
                Z Offline
                ZurdoDev
                wrote on last edited by
                #46

                Wiep Corbier wrote:

                For the next C# version I would like the ability to have multiple classes with the same name.

                You'd have to contact Microsoft.

                Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

                1 Reply Last reply
                0
                • W Wiep Corbier

                  Hi Pete, All these problems are already solved by me. Again. I store Skills as a string in the database. They are stored like this: Skill 1|Skill 2|Skill 3|Skill 4 of course the data is different but I show you the idea Then, customers (being developers) asked me if i couldn't provide a class with data stored in Skills as a list A list Skills has "items"

                  public class Skill
                  {
                      public string Item { get; set; }
                  }
                  

                  It doesn't matter if there is data in it, I handle that. So, I said to my customers I could do what the want but they need to address another Class:

                  CandidateFunctionWithSkillsList

                  No problem. But it made me think: what if my customers could make a choise how to recieve the data using the same name for the claas but had the option how it was presented/formatted. It is just something I would like. So I went on searching and discovered there were alternatives. But not exactly what I want. It doesn't exist. So, my question to the C# team is: can you make it happen in a next release.

                  K Offline
                  K Offline
                  kalberts
                  wrote on last edited by
                  #47

                  Wiep Corbier wrote:

                  what if my customers could make a choise how to recieve the data using the same name for the claas but had the option how it was presented/formatted.

                  So why don't you provide that in the one class you've got? dotNet doesn't know how to ask the customer - their language, preferred terminology, CLI or GUI, how your GUI is laid out and how the selection list should be presented. You do. You are the only one who can ask the customer in a proper way, and from the selected alternative initialized the object this way or that way. Or if you insist, create an object of this or that class. Two accessor methods of a given class may very well reference the same private data, presenting it in different formats (or set functions parsing value in different ways before storing it in the private value). You would have an explicitly declared internal value, not implicitly declared ones, so the simple {get; set;} would be relpaced with e.g. for the list format:

                  { get { return skills.Split('|'); }
                  set { skills = string.Join("|", value); }}

                  In this case, "skills" may actually be the implicitly declared variable from your string based accessor. Your (single) class may have as many different accessors (here: presentation formats) as you like. Of course you may have have initializers as well accepting intial values in either format, but being parsed and stored in one common format. If you are using this "skills" case as a simple way of illustrating what you think should be a commonly available mechanism for a lot of different purposes, then you should come up with a better illustration of the need. If your real problem is accessing the list of skills as a list or as a string, then it is handled by two properties (accessors) presenting the skills in two different ways from the one class. If you insist on two different classes with a single name, they will be different (you asked for it, you got it) - different set of members, different methods, different semantics. In the general case, only the name would be the same. You may construct examples where two different classes happen to have some members with similar names and somewhat similar semantics, while others differ. The overlap is more or less "accidental"; a general mechanism could not require "> x% similarity between same-name classes", it would be general (sic!). We have a general object class - it is called "object". Your proposal is, in the generaliz

                  W 1 Reply Last reply
                  0
                  • Z ZurdoDev

                    Wiep Corbier wrote:

                    Maybe, this skill is on position 998 Do a find: it will seach at least 998 items in a list before that skill is found

                    Actually, that's what indexes on a database table are for. If you had a Skills table it would not have to do a table scan to find the specific skill you wanted. And it would actually be much much faster than checking all the strings to see if it contains. You would use foreign keys and it would be magnitudes faster than doing a LIKE statement.

                    Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

                    W Offline
                    W Offline
                    Wiep Corbier
                    wrote on last edited by
                    #48

                    Thanks, this looks like a good idea. Don't remember why I dismissed it years ago, because this is the way I do this normally. I'll get back on it.

                    W 1 Reply Last reply
                    0
                    • Z ZurdoDev

                      Wiep Corbier wrote:

                      Maybe, this skill is on position 998 Do a find: it will seach at least 998 items in a list before that skill is found

                      Actually, that's what indexes on a database table are for. If you had a Skills table it would not have to do a table scan to find the specific skill you wanted. And it would actually be much much faster than checking all the strings to see if it contains. You would use foreign keys and it would be magnitudes faster than doing a LIKE statement.

                      Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

                      OriginalGriffO Offline
                      OriginalGriffO Offline
                      OriginalGriff
                      wrote on last edited by
                      #49

                      Want to bet he doesn't redesign? :laugh:

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                      1 Reply Last reply
                      0
                      • D Dave Kreskowiak

                        Just because "it's worked for years", doesn't mean it was designed properly. The list of skills NEVER should have been a string holding multiple values like that. It should have been a separate table with foreign keys back to the people that have those skills. The skill is stored ONCE and can be used multiple times. This saves space in the database. It's not the language that needs to updated to support your poor skills. It's your skills that need to be updated to better support your customers.

                        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                        Dave Kreskowiak

                        OriginalGriffO Offline
                        OriginalGriffO Offline
                        OriginalGriff
                        wrote on last edited by
                        #50

                        Dave Kreskowiak wrote:

                        It's not the language that needs to updated to support your poor skills. It's your skills that need to be updated to better support your customers.

                        Hear hear! :applause:

                        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

                        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                        1 Reply Last reply
                        0
                        • W Wiep Corbier

                          The list of skills NEVER should have been a string holding multiple values like that. It should have been a separate table with foreign keys That was my original idea too. Very logical. I would do it also, even as a habit BUT By exeption I will explain: Take a skills list with 1000 skills. Put them in a list. Now find and skill item with the value "Skill 1" Maybe, this skill is on position 998 Do a find: it will seach at least 998 items in a list before that skill is found Do a contains on a string and there is one search. If(Skill.Contains("|Skill 1|")) than, a Yes or a No. True or False. If I'm wrong, I will redesign.

                          K Offline
                          K Offline
                          kalberts
                          wrote on last edited by
                          #51

                          If my skill is "baking breads|cakes" it won't work as you expect it to. If you frequently will search lists of 1000 skills, you should rather put them in a dictionary (i.e. hash table). That would work even with "baking breads|cakes". Another side is that if you measure the time to search a 1000 element list, you'd probably be surprised by how fast it is. If the search is initated due to a user interaction, all the other stuff involved will require magnitudes more resources. Worry about the time for searching an in-memory list only if it is done thousands or tens of thousands times for each user interaction.

                          W 1 Reply Last reply
                          0
                          • K kalberts

                            If my skill is "baking breads|cakes" it won't work as you expect it to. If you frequently will search lists of 1000 skills, you should rather put them in a dictionary (i.e. hash table). That would work even with "baking breads|cakes". Another side is that if you measure the time to search a 1000 element list, you'd probably be surprised by how fast it is. If the search is initated due to a user interaction, all the other stuff involved will require magnitudes more resources. Worry about the time for searching an in-memory list only if it is done thousands or tens of thousands times for each user interaction.

                            W Offline
                            W Offline
                            Wiep Corbier
                            wrote on last edited by
                            #52

                            The list are not bigger than 80 items. My solution is already super fast. That's not the problem. btw: I'm aware of dictonary.

                            K 1 Reply Last reply
                            0
                            • K kalberts

                              Wiep Corbier wrote:

                              what if my customers could make a choise how to recieve the data using the same name for the claas but had the option how it was presented/formatted.

                              So why don't you provide that in the one class you've got? dotNet doesn't know how to ask the customer - their language, preferred terminology, CLI or GUI, how your GUI is laid out and how the selection list should be presented. You do. You are the only one who can ask the customer in a proper way, and from the selected alternative initialized the object this way or that way. Or if you insist, create an object of this or that class. Two accessor methods of a given class may very well reference the same private data, presenting it in different formats (or set functions parsing value in different ways before storing it in the private value). You would have an explicitly declared internal value, not implicitly declared ones, so the simple {get; set;} would be relpaced with e.g. for the list format:

                              { get { return skills.Split('|'); }
                              set { skills = string.Join("|", value); }}

                              In this case, "skills" may actually be the implicitly declared variable from your string based accessor. Your (single) class may have as many different accessors (here: presentation formats) as you like. Of course you may have have initializers as well accepting intial values in either format, but being parsed and stored in one common format. If you are using this "skills" case as a simple way of illustrating what you think should be a commonly available mechanism for a lot of different purposes, then you should come up with a better illustration of the need. If your real problem is accessing the list of skills as a list or as a string, then it is handled by two properties (accessors) presenting the skills in two different ways from the one class. If you insist on two different classes with a single name, they will be different (you asked for it, you got it) - different set of members, different methods, different semantics. In the general case, only the name would be the same. You may construct examples where two different classes happen to have some members with similar names and somewhat similar semantics, while others differ. The overlap is more or less "accidental"; a general mechanism could not require "> x% similarity between same-name classes", it would be general (sic!). We have a general object class - it is called "object". Your proposal is, in the generaliz

                              W Offline
                              W Offline
                              Wiep Corbier
                              wrote on last edited by
                              #53

                              I have read you contribution. Thanks for that. What I want doesn't exist and I'm not interested in alternatives that already exists. I want something new. I want the team that creates C# to make that happen. All of you think I have a dumb idea. But for me, inheritances is dumb. Interfaces are dumb, and many more Why? You don't need them. There are other ways to do the same. But they exist because someone had the idea and others liked it. The difference is, they understand it. Nobody understands my idea. Doesn't matter, I'm used to it. ps: I don't want a class with two representation of the skill data. I just do not want that. (of course it's an idea that crossed my mind)

                              K R realJSOPR 3 Replies Last reply
                              0
                              • W Wiep Corbier

                                I have read you contribution. Thanks for that. What I want doesn't exist and I'm not interested in alternatives that already exists. I want something new. I want the team that creates C# to make that happen. All of you think I have a dumb idea. But for me, inheritances is dumb. Interfaces are dumb, and many more Why? You don't need them. There are other ways to do the same. But they exist because someone had the idea and others liked it. The difference is, they understand it. Nobody understands my idea. Doesn't matter, I'm used to it. ps: I don't want a class with two representation of the skill data. I just do not want that. (of course it's an idea that crossed my mind)

                                K Offline
                                K Offline
                                kalberts
                                wrote on last edited by
                                #54

                                Wiep Corbier wrote:

                                ps: I don't want a class with two representation of the skill data. I just do not want that.

                                But I suggest a single reperesentation! Two representations would be really bad design. Two different presentations is a completely different thing. It is like when your code handles a binary integer, you don't present it like a binary integer but format it into a character string. You may format it as hex, octal, decimal, with or without leading zeroes, trailing currency sign or whatever. For binary reals you print out the number of decimal positions according to need. The internal integer or real binary value is unique and unaffected by the presentation format. Similar with you skills list. Whether it is stored as a single string with | separators, a list, a dictionary or as a database table doesn't matter: From that unique representation you may format it as a string, as a list or in any other format. For console output, you use different Format or ToString format strings, for binary formats, you use different accessors (that may also use Format/ToString when appropriate). An accessor isn't a representation. It is an accessor, a way to get at a representation. The representation is independent of it.

                                1 Reply Last reply
                                0
                                • W Wiep Corbier

                                  The list are not bigger than 80 items. My solution is already super fast. That's not the problem. btw: I'm aware of dictonary.

                                  K Offline
                                  K Offline
                                  kalberts
                                  wrote on last edited by
                                  #55

                                  Wiep Corbier wrote:

                                  My solution is already super fast.

                                  So don't worry about the expense of searching an 80 item list. Even though a straight search in a simple string is super fast, it does not imply that other alternatives are unacceptably slow.

                                  W 1 Reply Last reply
                                  0
                                  • K kalberts

                                    Wiep Corbier wrote:

                                    My solution is already super fast.

                                    So don't worry about the expense of searching an 80 item list. Even though a straight search in a simple string is super fast, it does not imply that other alternatives are unacceptably slow.

                                    W Offline
                                    W Offline
                                    Wiep Corbier
                                    wrote on last edited by
                                    #56

                                    I agree :) Everywhere else I use a different approach like list, dictonary etc I use ms sql server databases. I love creating related tables. It's what I do all the time. But this time only I took a different path. (

                                    1 Reply Last reply
                                    0
                                    • W Wiep Corbier

                                      For the next C# version I would like the ability to have multiple classes with the same name. But, this is for POCO's What do I mean? I have an poco with the name CandidateFunction

                                      public class CandidateFunction
                                      {
                                          public int CandidateFunctionId { get; set; }
                                          public int CandidateId { get; set; }
                                          public int FunctionId { get; set; }
                                          public string Skills { get; set; }
                                          public DateTime Date { get; set; }
                                      }
                                      

                                      As you can see, the property with the name Skills is a string. It can be a long string and it stores one or more Skills. But customers want to see Skills as a list so I have another POCO

                                      public class CandidateFunctionWithSkillsList
                                      {
                                          public int CandidateFunctionId { get; set; }
                                          public int CandidateId { get; set; }
                                          public int FunctionId { get; set; }
                                          public List Skills { get; set; }
                                          public DateTime Date { get; set; }
                                      }
                                      

                                      It has another name. Now, I want both POCO's with the same name. I know there alternatives for what I want but I don't like them. So, when I instantiate a new CandidateFunction, I want a popup asking me which one I want to use. Will this ever happen and if not, why not?

                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #57

                                      Whose "popup"? You'll need a separate NAMESPACE for each DUPLICATE CLASS NAME. Then you can "code logic" for YOUR "popup" or whatever. And in your CODE, you qualify with a NAMESPACE that VS can resolve with (Intellisense-wise). There is no other magic; it's all in the head. YOU are the only "customer" at this stage. Beyond that, you use "Interfaces".

                                      It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                                      1 Reply Last reply
                                      0
                                      • W Wiep Corbier

                                        For the next C# version I would like the ability to have multiple classes with the same name. But, this is for POCO's What do I mean? I have an poco with the name CandidateFunction

                                        public class CandidateFunction
                                        {
                                            public int CandidateFunctionId { get; set; }
                                            public int CandidateId { get; set; }
                                            public int FunctionId { get; set; }
                                            public string Skills { get; set; }
                                            public DateTime Date { get; set; }
                                        }
                                        

                                        As you can see, the property with the name Skills is a string. It can be a long string and it stores one or more Skills. But customers want to see Skills as a list so I have another POCO

                                        public class CandidateFunctionWithSkillsList
                                        {
                                            public int CandidateFunctionId { get; set; }
                                            public int CandidateId { get; set; }
                                            public int FunctionId { get; set; }
                                            public List Skills { get; set; }
                                            public DateTime Date { get; set; }
                                        }
                                        

                                        It has another name. Now, I want both POCO's with the same name. I know there alternatives for what I want but I don't like them. So, when I instantiate a new CandidateFunction, I want a popup asking me which one I want to use. Will this ever happen and if not, why not?

                                        P Offline
                                        P Offline
                                        Patrice T
                                        wrote on last edited by
                                        #58

                                        Wiep Corbier wrote:

                                        So, when I instantiate a new CandidateFunction, I want a popup asking me which one I want to use.

                                        Making 2 classes indistinguishable is a bad idea to the core. In 35 years, I never came to a case that need such Gremlin.

                                        Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein

                                        1 Reply Last reply
                                        0
                                        • W Wiep Corbier

                                          Thanks, this looks like a good idea. Don't remember why I dismissed it years ago, because this is the way I do this normally. I'll get back on it.

                                          W Offline
                                          W Offline
                                          Wiep Corbier
                                          wrote on last edited by
                                          #59

                                          I've thought about it, and it's time to switch to subtables. I started that now. Thanks for the anwers all participants.

                                          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