M
mp
it seems i've seen articles warning against excessive use of inheritance
"is a" vs "has a"
i think this is a sample of "is a" ... i don't know how i'd make it a "has
a" sample
i was thinking to try a simple inheritance like the following
public class Investment
{
public Investment()
{ }
public Investment(string name)
{
_name = name; //,<<every investment would have a name
}
public string Name { get; set; }
}
class Stock : Investment
{
public string Ticker { get; set; }//,< stocks have ticker symbol
}
class RealEstate : Investment
{
public string Address { get; set; }//<< houses have address
}
is that sort of how inheritance works?
ie save having to add multiple definitions of name in each subclass
and would deriving from investment like that affect xmlSerializing
a list of subtypes
other problems/advantages of this type of structure?
thanks
mark
"is a" vs "has a"
i think this is a sample of "is a" ... i don't know how i'd make it a "has
a" sample
i was thinking to try a simple inheritance like the following
public class Investment
{
public Investment()
{ }
public Investment(string name)
{
_name = name; //,<<every investment would have a name
}
public string Name { get; set; }
}
class Stock : Investment
{
public string Ticker { get; set; }//,< stocks have ticker symbol
}
class RealEstate : Investment
{
public string Address { get; set; }//<< houses have address
}
is that sort of how inheritance works?
ie save having to add multiple definitions of name in each subclass
and would deriving from investment like that affect xmlSerializing
a list of subtypes
other problems/advantages of this type of structure?
thanks
mark