我有一个Person
班级,并且基于我在这篇文章中收到的一些帮助。
MonoState、Singleton 或派生形式:CRUD 应用程序的最佳方法?
我有一CurrentPerson
堂课(??)它,我通过它访问数据。
我想我理解这应该如何工作,但似乎我做得不太对。
问题:
对于初学者来说,
Person
它的所有成员变量不应该是私有的吗?为什么
Person
在声明时是CurrentPerson
静态的?是对的吗?Person
实际上有子对象Address
,Enrollment
和CaseNote
. 我如何合并它们?一个CurrentEnrollment
包装Enrollment
?
作为一门应用科学,我对 OOP 相当陌生,因此其中一些概念对我来说很难想象。
代码很长,请见谅。
class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string MiddleName { get; set; }
public string SuffixID { get; set; }
public string TitleID { get; set; }
public string SocialSn { get; set; }
public string Gender { get; set; }
public string DlNumber { get; set; }
public string DlStateID { get; set; }
public string PrimaryRace { get; set; }
public string SecondaryRace { get; set; }
public string EmailAddress { get; set; }
public string MaritalStatus { get; set; }
public string InsertProgram { get; set; }
public string InsertUserID { get; set; }
public string UpdateProgram { get; set; }
public string UpdateUserID { get; set; }
public string LockID { get; set; }
public int PersonID { get; set; }
public int ClientID { get; set; }
public int ResidencyCountyID { get; set; }
public int ResponsibilityCountyID { get; set; }
public bool HispanicOriginFlag { get; set; }
public bool CitizenFlag { get; set; }
public bool VeteranFlag { get; set; }
public DateTime BirthDate { get; set; }
public DateTime DeathDate { get; set; }
public DateTime InsertDateTime { get; set; }
public DateTime UpdateDateTime { get; set; }
}
class CurrentPerson
{
public static Person Person { get; set; }
public string FirstName
{
get { return CurrentPerson.Person.FirstName; }
set { CurrentPerson.Person.FirstName = value; }
}
public string LastName
{
get { return CurrentPerson.Person.LastName; }
set { CurrentPerson.Person.LastName = value; }
}
public string MiddleName
{
get { return CurrentPerson.Person.MiddleName; }
set { CurrentPerson.Person.MiddleName = value; }
}
public string SuffixID
{
get { return CurrentPerson.Person.SuffixID; }
set { CurrentPerson.Person.SuffixID = value; }
}
public string TitleID
{
get { return CurrentPerson.Person.TitleID; }
set { CurrentPerson.Person.TitleID = value; }
}
public string SocialSn
{
get { return CurrentPerson.Person.SocialSn; }
set { CurrentPerson.Person.SocialSn = value; }
}
public string Gender
{
get { return CurrentPerson.Person.Gender; }
set { CurrentPerson.Person.Gender = value; }
}
public string DlNumber
{
get { return CurrentPerson.Person.DlNumber; }
set { CurrentPerson.Person.DlNumber = value; }
}
public string DlStateID
{
get { return CurrentPerson.Person.DlStateID; }
set { CurrentPerson.Person.DlStateID = value; }
}
public string PrimaryRace
{
get { return CurrentPerson.Person.PrimaryRace; }
set { CurrentPerson.Person.PrimaryRace = value; }
}
public string SecondaryRace
{
get { return CurrentPerson.Person.SecondaryRace; }
set { CurrentPerson.Person.SecondaryRace = value; }
}
public string EmailAddress
{
get { return CurrentPerson.Person.EmailAddress; }
set { CurrentPerson.Person.EmailAddress = value; }
}
public string MaritalStatus
{
get { return CurrentPerson.Person.MaritalStatus; }
set { CurrentPerson.Person.MaritalStatus = value; }
}
public string InsertProgram
{
get { return CurrentPerson.Person.InsertProgram; }
set { CurrentPerson.Person.InsertProgram = value; }
}
public string InsertUserID
{
get { return CurrentPerson.Person.InsertUserID; }
set { CurrentPerson.Person.InsertUserID = value; }
}
public string UpdateProgram
{
get { return CurrentPerson.Person.UpdateProgram; }
set { CurrentPerson.Person.UpdateProgram = value; }
}
public string UpdateUserID
{
get { return CurrentPerson.Person.UpdateUserID; }
set { CurrentPerson.Person.UpdateUserID = value; }
}
public string LockID
{
get { return CurrentPerson.Person.LockID; }
set { CurrentPerson.Person.LockID = value; }
}
public int PersonID
{
get { return CurrentPerson.Person.PersonID; }
set { CurrentPerson.Person.PersonID = value; }
}
public int ClientID
{
get { return CurrentPerson.Person.ClientID; }
set { CurrentPerson.Person.ClientID = value; }
}
public int ResidencyCountyID
{
get { return CurrentPerson.Person.ClientID; }
set { CurrentPerson.Person.ClientID = value; }
}
public int ResponsibilityCountyID
{
get { return CurrentPerson.Person.ResponsibilityCountyID; }
set { CurrentPerson.Person.ResponsibilityCountyID = value; }
}
public bool HispanicOriginFlag
{
get { return CurrentPerson.Person.HispanicOriginFlag; }
set { CurrentPerson.Person.HispanicOriginFlag = value; }
}
public bool CitizenFlag
{
get { return CurrentPerson.Person.CitizenFlag; }
set { CurrentPerson.Person.CitizenFlag = value; }
}
public bool VeteranFlag
{
get { return CurrentPerson.Person.VeteranFlag; }
set { CurrentPerson.Person.VeteranFlag = value; }
}
public DateTime BirthDate
{
get { return CurrentPerson.Person.BirthDate; }
set { CurrentPerson.Person.BirthDate = value; }
}
public DateTime DeathDate
{
get { return CurrentPerson.Person.DeathDate; }
set { CurrentPerson.Person.DeathDate = value; }
}
public DateTime InsertDateTime
{
get { return CurrentPerson.Person.InsertDateTime; }
set { CurrentPerson.Person.InsertDateTime = value; }
}
public DateTime UpdateDateTime
{
get { return CurrentPerson.Person.UpdateDateTime; }
set { CurrentPerson.Person.UpdateDateTime = value; }
}
}
PS 如果 Daniel Brückner 碰巧读到了这篇文章,请不要冒犯,因为我不是在猜测你的答案;我只需要对某些项目进行更深入的说明,以便正确理解单态在我的应用程序中的使用。