c# - Can we access derived class properties by using base class object? -
this question has answer here:
can access derived class properties using base class object?
i having base class
public abstract class fnmarecord { public int id { get; set; } public abstract string prefix { get; } }
and there many derived classes inherits fnmarecord class
public class transactionheader : fnmarecord { public override string prefix { {return "th";} } public static readonly string transactionid = "t100099-002"; public string transactioncontrolnumber { get; set; } } public class titleholder : fnmarecord { public override string prefix { {return "02c";} } public string titleholdername { get; set; } }
now can use instance of fnmarecord in class access property in titleholder?
no. fredrik mörk states in their answer here:
base class not (and more importantly should not) know derived class properties. different derived classes have different set of added properties. making base class aware of counteract important principles of object oriented design
Comments
Post a Comment