Articles Tagged ‘learning c# and .net’...You're It.

This post is going to cover a pair of topics that aren’t truly related, but topics that I like to use together. When combined they can give you a nice pattern. First I’m going to briefly talk about the Null Object Pattern:

The Null Object Pattern

Rather than dealing with uninitialized variable instances, you can start off by assigning a variable to an instance of a “Null Object”. Oftentimes you’ll see this done when developers assign an empty string to a variable because they don’t want to deal with null values. I’m going to be discussing this with types that are a bit more complex than string.

In the code snippet below, I have represented a method with an optional argument that will fall back to an “empty” signature if one isn’t supplied. This Empty property is our Null Object for Signature that provides a safe instance we can use instead of dealing with null.

public void ApplySignature(Signature signature = null)
{
    var signatureToApply = signature ?? Signature.Empty;

    // sign things...
}


public class Signature
{
    public Signature(EmailUser user) : this()
    {
        if (user == null)
            throw new ArgumentNullException("user", "A Signature must be created for a valid user");

        User = user;
    }

    private Signature()
    {
        RichText = "";
    }

    public EmailUser User { get; private set; }

    public string RichText { get; set; }

    public static Signature Empty
    {
        get { return new Signature(); }
    }

    public override string ToString()
    {
        return RichText;
    }
}
view raw Signature.cs This Gist brought to you by GitHub.
Read the rest of this entry »


 

Steve DonieWhen Steve Donie was hired as a Principal Consultant at Headspring in early 2011, he hit the ground running.  His first day on the job, he started as the project lead for EPA Systems, designing a system for tracking greenhouse gasses for a large oil and gas company.  He encompasses the solutions based approach that we covet so much at Headspring and in life.  At home, Steve and his father worked on a massive project digitizing hundreds of family photos from their original slides onto an online portal for their entire family to share.  He is also the webmaster for his local high school’s swim team. And when he is not plugging away on a computer, he can be designing and building furniture, or enjoying the company of his two brilliant daughters.

Basically, getting to know Steve meant getting to know how diverse his background truly is, and his desire to really involve himself in the world that surrounds him.  Here is some of what we talked about:

Read the rest of this entry »