c# - Can we access derived class properties by using base class object? -


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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -