Click here to Skip to main content
14,634,296 members
Home » Discussions » C#
   

C#

 
GeneralRe: Multiple Classes, same name Pin
Member 798912216-Jun-20 3:13
MemberMember 798912216-Jun-20 3:13 
GeneralRe: Multiple Classes, same name Pin
Richard MacCutchan16-Jun-20 3:50
mveRichard MacCutchan16-Jun-20 3:50 
GeneralRe: Multiple Classes, same name Pin
Nelek22-Jun-20 5:58
protectorNelek22-Jun-20 5:58 
GeneralRe: Multiple Classes, same name Pin
Dave Kreskowiak16-Jun-20 3:22
mveDave Kreskowiak16-Jun-20 3:22 
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier16-Jun-20 3:26
MemberWiep Corbier16-Jun-20 3:26 
GeneralRe: Multiple Classes, same name Pin
Dave Kreskowiak16-Jun-20 3:42
mveDave Kreskowiak16-Jun-20 3:42 
GeneralRe: Multiple Classes, same name Pin
ZurdoDev16-Jun-20 4:00
mveZurdoDev16-Jun-20 4:00 
AnswerRe: Multiple Classes, same name Pin
Pete O'Hanlon16-Jun-20 1:45
subeditorPete O'Hanlon16-Jun-20 1:45 
I'm going to start by pointing out the most obvious thing. Your two POCO's have different implementations. Bear with me, because this is important for the rest of the discussion.

As these two POCO's have different properties, you have an immediate issue which is, what happens when you want to consume your code? You have Skills as a string in one, and a List of strings in the other. The code that calls this is going to have to conditionally choose the operations to perform on the Skills based on the "popup". Now, you might have additional operations that chain off those operations, so you might have a POCO Skill class that looks like this:
public class Skill
{
  public int SkillId { get; set; }
  public string SkillRange { get; set; }
}
and another one that looks like this:
public class Skill
{
  public int SkillId { get; set; }
  public List<SkillRange> SkillRange { get; set; }
}
And maybe you have another class that looks like this
public class Skill
{
  public Guid SkillId { get; set; }
  public string SkillRange { get; set; }
}
For good measure, our codebase has this one thrown in
public class Skill
{
  public Guid SkillId { get; set; }
  public List<string> SkillRange { get; set; }
}
We are creating a real mess of code here that we are expecting someone to be able to grok easily. The more we add to the code base, the harder it will be to keep these in line, and we have violated clear code principles. Why have we violated this? Suppose we have some consuming code that looks like this:
Skill skill = GetPopulatedSkill();
var id = skill.SkillId;
ValidateSkillRange(skill.SkillRange);
What validation are you expecting ValidateSkillRange to be doing? Is it a string.IsNullOrWhiteSpace check? Perhaps you just want to ensure it's not an empty list. Perhaps you need to iterate over items in the list and check certain values in there. The problem is, unless you start covering all of the different combinations of cases, the compiler isn't going to have the last scooby of a clue how to fix this, even if the user, by luck, picks the correct one. Bear in mind that you may have different parts of your code needing different Skill implementations at different points; you're expecting the user to be able to guess which one needs to apply at each point in the chain. This is not a useful feature, and it's certainly not one you could test.

If you don't believe us, please raise it as a feature request against C# (the language is open source after all). Perhaps you'll believe them.

GeneralRe: Multiple Classes, same name Pin
Wiep Corbier16-Jun-20 1:58
MemberWiep Corbier16-Jun-20 1:58 
GeneralRe: Multiple Classes, same name Pin
OriginalGriff16-Jun-20 2:28
mveOriginalGriff16-Jun-20 2:28 
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier16-Jun-20 2:33
MemberWiep Corbier16-Jun-20 2:33 
GeneralRe: Multiple Classes, same name Pin
OriginalGriff16-Jun-20 2:45
mveOriginalGriff16-Jun-20 2:45 
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier16-Jun-20 3:10
MemberWiep Corbier16-Jun-20 3:10 
GeneralRe: Multiple Classes, same name Pin
Dave Kreskowiak16-Jun-20 3:32
mveDave Kreskowiak16-Jun-20 3:32 
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier16-Jun-20 3:54
MemberWiep Corbier16-Jun-20 3:54 
AnswerRe: Multiple Classes, same name Pin
ZurdoDev16-Jun-20 4:04
mveZurdoDev16-Jun-20 4:04 
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier16-Jun-20 4:21
MemberWiep Corbier16-Jun-20 4:21 
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier16-Jun-20 9:32
MemberWiep Corbier16-Jun-20 9:32 
GeneralRe: Multiple Classes, same name Pin
OriginalGriff16-Jun-20 4:27
mveOriginalGriff16-Jun-20 4:27 
GeneralRe: Multiple Classes, same name Pin
Member 798912216-Jun-20 4:28
MemberMember 798912216-Jun-20 4:28 
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier16-Jun-20 4:32
MemberWiep Corbier16-Jun-20 4:32 
GeneralRe: Multiple Classes, same name Pin
Member 798912216-Jun-20 5:52
MemberMember 798912216-Jun-20 5:52 
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier16-Jun-20 6:04
MemberWiep Corbier16-Jun-20 6:04 
GeneralRe: Multiple Classes, same name Pin
OriginalGriff16-Jun-20 4:28
mveOriginalGriff16-Jun-20 4:28 
GeneralRe: Multiple Classes, same name Pin
Pete O'Hanlon16-Jun-20 3:32
subeditorPete O'Hanlon16-Jun-20 3:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.