2011-06-12 68 views
2

我正在嘗試爲學生和教師創建一個社交網絡應用程序。 我目前在設計用戶賬戶模塊如何在系統中設計兩種類型的帳戶

我還以爲這兩種方法的

方法1

Public class Account 
{ 
    public string AccountId{get;set;} 
    public string AccountName{get;set;} 
     . 
     . 
     . 


} 

public class Student : Account 
{ 
    public Course[] Courses {get; set;} 
    //other student properties 
     . 
     . 
     . 

} 

public class Teacher : Account 
{ 
    //other teacher properties 

} 

方法2

Public class Account 
{ 
    public string AccountId{get;set;} 
    public string AccountName{get;set;} 
    public AccountType AccountType {get;set;} //AccontType is enum having student and teacher 
     . 
     . 
     . 


} 


public class User 
{ 
    public string UserId { get;set;} 
    public string UserName {get;set;} 
    public Account Account {get;set;} 
} 


public class Student : User 
{ 
    public Course[] Courses {get; set;} 
    //other student properties 
     . 
     . 
     . 

} 


public class Teacher : User 
{ 
    //other teacher properties 

} 

有什麼比這些方法更好的方法?

回答

2

方法2在我看來更清晰和首選。

什麼它歸結爲是做了User有一個帳戶一個User賬號?對於我來說,前者和你應該在方法2中使用組合而不是繼承。

+0

你有沒有遇到過這樣的場景......並且有沒有關於這個的任何標準實踐... – 2011-06-12 08:17:12

1

我更喜歡方法2,因爲它更接近現實世界場景。學生和教師用戶,其中每個人都有一個帳戶具有所需的屬性集。

相關問題