Common Reusable Business Entities Part 2

This is part two of an ongoing series on common reusable business entities. This series does not need to be read in order, but here are the preceeding posts if you would like to catch up:

In this post, we’re going to examine a short but useful structure that can be used in almost every business-style application you will write; the Address structure.

Address Structure

The Address structure specifies information regarding a physical mailing address. Obviously, this is used all over the place, but a few examples include E-Commerce shipping and billing addresses, user profile addresses, and a foundation for geocoding property/locations. Overall, all of the entities to be demonstrated in this short series are meant to be thin, without a lot of functionality or business logic.

public struct Address
{
    #region "PROPERTIES"

    /// <summary>
    /// The prefix of the street address.  (Ex: 1400 Pennsylvania Ave.)
    /// </summary>
    public string Address1 { get; set; }

    /// <summary>
    /// The suffix of the street address.  (Ex: Apt. 14)
    /// </summary>
    public string Address2 { get; set; }

    /// <summary>
    /// The city of the address.
    /// </summary>
    public string City { get; set; }

    /// <summary>
    /// The state of the address (2 character string - could be entity).
    /// </summary>
    public string State { get; set; }  //NOTE: it may be more appropriate to have this as an object

    /// <summary>
    /// The country of the address (3 character representation: USA, CHN, JPN)
    /// </summary>
    public string Country { get; set; }  //NOTE: it may be more appropriate to have this as an object

    /// <summary>
    /// The postal code of the address.
    /// </summary>
    public string Zip { get; set; }  

    #endregion

    #region "CONSTRUCTORS"

    /// <summary>
    /// Constructor for address.
    /// </summary>
    /// <param name="address1"></param>
    /// <param name="address2"></param>
    /// <param name="city"></param>
    /// <param name="state"></param>
    /// <param name="country"></param>
    /// <param name="zip"></param>
    public Address(string address1, string address2, string city, string state, string country, string zip)
        : this()
    {
        this.Address1 = address1;
        this.Address2 = address2;
        this.City = city;
        this.State = state;
        this.Country = country;
        this.Zip = zip;
    }

    #endregion

    #region "METHODS"

    /// <summary>
    /// Overrides ToString() to display default address format (Address1 Address2 City, State Zip).
    /// </summary>
    /// <returns></returns>
    public override string ToString()
    {
        return (this.Address1 + " " + this.Address2 + " " + this.City + ", " + this.State + " " + this.PostalCode);
    }

    #endregion
}

What’s Next?

I’ll cover three short entities in the next part; SocialSecurityNumber, CreditCardNumber and PhoneNumber, so feel free to come back and check it out. Also, please add any requests for specific common entities or add your own in the comments below.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s