Mark all posts that give the desired result the answer. If you only mark the last that gave you clarification because you misread an earlier post others will be confused. Some of us are here to help others and our point to post ratio matters.
you are right in that there is no multiple inheritance
but remember that inheritance is not about reusing properties but modeling the reality, there should be always an "is a" relation between the classes involved.
With your class names it doesn't make much sense but I assume they are maid up for the example. Here you will ask: Communicate "is a" CallMe? only if your answer is yes, you will create the relation, not just because you want to reuse the properties.
Not just because 2 classes have similar properties they necessarily have to have an inheritance relation.
Other thing, you said you dont want composition(meaning communication having properties callme and phoneme) you should actually favor composition over inheritance, check this article: https://en.wikipedia.org/wiki/Composition_over_inheritance
depending on your particular case this may solve your issue:
public class Communicate
{
public string Name {get;set;}
}
public class CallMe : Comunicate
{
public int PhoneNumber {get;set;}
}
public class MailMe : Comunicate
{
public string Email {get;set;}
}
Now I will call your classes:
Communicate: ContactInformation
CallMe: PhoneInformation
MailMe: EmailInformation
-- Remembert to mark as answer if it solves your issue
-----------------
Please remember to click "Mark as Answer" the responsES that resolved your issue.
Member
4 Points
95 Posts
How to inhert from multiple place..I know .net wont support multiple inheritace...but is there an...
May 24, 2017 05:13 PM|bsurendiran|LINK
Lets say I have below class
public class CallMe
{
public int PhoneNumber {get;set;}
}
public class MailMe
{
public string Email {get;set;}
}
Now
I want to create a class with has all the properites of Callme and MailMe
like
public class Communicate :Callme,MailMe
{
public string Name {get;set;}
}
I dont want CallMe and MailMe as property for Communicate...
How to do this
Contributor
7048 Points
2189 Posts
Re: How to inhert from multiple place..I know .net wont support multiple inheritace...but is ther...
May 24, 2017 05:34 PM|ryanbesko|LINK
https://en.wikipedia.org/wiki/Multiple_inheritance#The_diamond_problem
Participant
1380 Points
608 Posts
Re: How to inhert from multiple place..I know .net wont support multiple inheritace...but is ther...
May 24, 2017 05:47 PM|JBetancourt|LINK
you are right in that there is no multiple inheritance
but remember that inheritance is not about reusing properties but modeling the reality, there should be always an "is a" relation between the classes involved.
With your class names it doesn't make much sense but I assume they are maid up for the example. Here you will ask: Communicate "is a" CallMe? only if your answer is yes, you will create the relation, not just because you want to reuse the properties.
Not just because 2 classes have similar properties they necessarily have to have an inheritance relation.
Other thing, you said you dont want composition(meaning communication having properties callme and phoneme) you should actually favor composition over inheritance, check this article: https://en.wikipedia.org/wiki/Composition_over_inheritance
depending on your particular case this may solve your issue:
Now I will call your classes:
Communicate: ContactInformation
CallMe: PhoneInformation
MailMe: EmailInformation
--
Remembert to mark as answer if it solves your issue
Please remember to click "Mark as Answer" the responsES that resolved your issue.