Refracted Paladin
Refracted Paladin

Reputation: 12216

Is this a proper MonoState Design?

I have a Person Class and based on some help I received in this post.

MonoState, Singleton, or Derived Forms: Best approach for CRUD app?

I have a CurrentPerson class around(??) it and I access the data thru that.

I think I understand how this is supposed to work but it seems that I don't have it quite right.

Questions:

  1. For starters, shouldn't Person and all it's member variables be private?

  2. Why is Person, when declared in CurrentPerson, static? Is that right?

  3. Person actually has child objects Address, Enrollment, and CaseNote. How do I incorporate them? A CurrentEnrollment wrapper around Enrollment?

I am fairly new to OOP as an applied science so some of these concepts are hard for me to visualize.

The code is long, I apologize.


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; }
    }


}

P.S. If Daniel Brückner happens to read this please take no offense as I am not second guessing your answer; I just need deeper clarification on some items in order to properly understand the use of monostate in my app.

Upvotes: 1

Views: 293

Answers (1)

upsidedowncreature
upsidedowncreature

Reputation:

Regarding whether the fields should be private, that's just the new (C# 3.0?) way of declaring properties without having a backing variable. A common variation is

public string SomeProperty { get; protected set }

'Course, as soon as you want to do something like validation in the setter this doesn't work and you have to go back to writing setters and getters, and declaring a backing variable.

I'm not sure what the intent of the static CurrentPerson.Person() method is, or how it gets set.

For the third question, if I understand you right you'd give the Person class a property of type Address and access it something like this:

Console.WriteLine(somePerson.HomeAddress.City);

Upvotes: 1

Related Questions