Chris Martin's Blog

A Developer and so on...

  Home  |   Contact  |   Syndication    |   Login
  7 Posts | 0 Stories | 22 Comments | 20 Trackbacks

News

Tag Cloud


Archives

Post Categories

Blogs I check out

Duration

Cold symptoms usually appear 2 or 3 days after exposure to a source of infection. Most colds clear up within 1 week, but some last for as long as 2 weeks.

Source: Common Cold

Hah. I should be so lucky!

 

[TestFixture]
public class Program
{
    static void Main(string[] args){}

    [Test]
    public void ChrisDoesntWriteCodeWhenSick()
    {
        IDeveloper chris = new Chris(new InsaneCommonColdThatLastsForAMonth());
        Assert.IsFalse(chris.CanWriteCode());
    }
}

public interface IDeveloper
{
    bool CanWriteCode();
}

public class Chris : IDeveloper
{
    private IHealth currentHealth;

    public Chris(IHealth currentHealth)
    {
        this.currentHealth = currentHealth;
        currentHealth.AnnounceHealth();
    }

    public bool CanWriteCode()
    {
        return currentHealth.CanWorkToday;
    }
}

public interface IHealth
{
    bool CanWorkToday { get; }

    void AnnounceHealth();
}

public class InsaneCommonColdThatLastsForAMonth : IHealth
{
    public bool CanWorkToday
    {
        get { return false; }
    }

    public void AnnounceHealth()
    {
        Console.WriteLine("CoughCoughCough...");
        Console.WriteLine("Ouch! My head!");
    }
}
posted on Friday, January 05, 2007 10:09 AM

Feedback

# re: Common Cold 1/5/2007 11:23 AM Tim Hibbard
That's probably the most complicated "communicating via code" example!

I like it.

# re: Common Cold 1/5/2007 2:14 PM Chris Martin
Thanks to ReSharper, I think I only typed like 5 characters total!!! LOL.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: