Click here to Skip to main content
14,602,455 members
   

C#

 
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 
GeneralRe: Multiple Classes, same name Pin
Member 798912216-Jun-20 4:19
MemberMember 798912216-Jun-20 4:19 
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 generalized sense, more or less to make an "object2" class: If the class name implies nothing about object members or semantics, it has no syntactic or semantic value. You have no clue about what to expect from an object of that name.

I am fully satisified with the classic "object" class. I don't see a need for an "object2" class.
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier16-Jun-20 4:46
MemberWiep Corbier16-Jun-20 4:46 
GeneralRe: Multiple Classes, same name Pin
Member 798912216-Jun-20 5:13
MemberMember 798912216-Jun-20 5:13 
SuggestionRe: Multiple Classes, same name Pin
Ralf Meier17-Jun-20 2:42
professionalRalf Meier17-Jun-20 2:42 
GeneralRe: Multiple Classes, same name Pin
#realJSOP21-Jun-20 1:39
mva#realJSOP21-Jun-20 1:39 
AnswerRe: Multiple Classes, same name Pin
ZurdoDev16-Jun-20 2:20
mveZurdoDev16-Jun-20 2:20 
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier16-Jun-20 2:26
MemberWiep Corbier16-Jun-20 2:26 
GeneralRe: Multiple Classes, same name Pin
ZurdoDev16-Jun-20 2:27
mveZurdoDev16-Jun-20 2:27 
AnswerRe: Multiple Classes, same name Pin
ZurdoDev16-Jun-20 4:05
mveZurdoDev16-Jun-20 4:05 
AnswerRe: Multiple Classes, same name Pin
Gerry Schmitz16-Jun-20 7:06
mveGerry Schmitz16-Jun-20 7:06 
AnswerRe: Multiple Classes, same name Pin
Patrice T16-Jun-20 8:06
mvePatrice T16-Jun-20 8:06 
AnswerRe: Multiple Classes, same name Pin
Mycroft Holmes16-Jun-20 12:46
professionalMycroft Holmes16-Jun-20 12:46 
AnswerRe: Multiple Classes, same name Pin
Simon_Whale17-Jun-20 2:23
professionalSimon_Whale17-Jun-20 2:23 
AnswerRe: Multiple Classes, same name Pin
#realJSOP21-Jun-20 1:35
mva#realJSOP21-Jun-20 1:35 
GeneralRe: Multiple Classes, same name Pin
Bohdan Stupak29-Jun-20 4:05
professionalBohdan Stupak29-Jun-20 4:05 
AnswerRe: Multiple Classes, same name Pin
Bohdan Stupak29-Jun-20 4:03
professionalBohdan Stupak29-Jun-20 4:03 
QuestionAuthentication Error After migration of .net web application from VS2012 (.net 4.0) to VS2019 (.net 4.7.2)project Pin
Rohith PH14-Jun-20 23:42
MemberRohith PH14-Jun-20 23:42 
AnswerRe: Authentication Error while migration of .net web application from VS2012 (.net 4.0) to VS2019 (.net 4.7.2)project Pin
Richard Deeming15-Jun-20 0:22
mveRichard Deeming15-Jun-20 0:22 

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.