c# 4.0 - C# Multiple Inheritance -


currently im studying c# asp.net mvc 4 code first approach. im visual basic developer, , want start c#. and, came accross situation i've manage multiple inheritance. but, not possible class thought. so, how should manage these classes have :

//i have following person class hold common properties  //and type of person e.g : student, faculty, administrative public class person {     public int id { get; set; }     public string firstname { get; set; }     public string lastname { get; set; }     public string type { get; set; } }   //this student class, derived person public class student:person {     public datetime dateofbirth { get; set; }     public datetime enrollmentdate { get; set; }     public string remarks { get; set; }       public bool approved { get; set; }     public datetime approveddate { get; set; }     public int approveduserid { get; set; } }   //this faculty class, derived person public class faculty : person {     public datetime hireddate { get; set; }       public bool approved { get; set; }     public datetime approveddate { get; set; }     public int approveduserid { get; set; } } 

what want make approved, approveddate, , approveduserid common. want specify properties :

 public class approve {     public bool approved { get; set; }     public datetime approveddate { get; set; }     public int approveduserid { get; set; } } 

and, want use :

public class student:person,approve {     public datetime dateofbirth { get; set; }     public datetime enrollmentdate { get; set; }     public string remarks { get; set; } } 

and, cannot put things inside person. because, i've use classes to, not person.

then, how achieve this...

please give me example above situation.

please help. and, thank in advance.

one possible solution modify hierarchy:

public class personwithapprove : person { // todo: replace non disgusting name     public bool approved { get; set; }     // etc... }  public class student : personwithapprove { }  public class faculty : personwithapprove { } 

or create interface:

public interface iapprove {     bool approved { get; set; }     // etc }  public class student : person, iapprove { } 

you might leave class approve such, , have classes property of type:

public class student : person {     approve _approve = new approve();     public approve approve {         { return _approve; }     } } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -