The meaning of “when”

Observe the difference between these two requirements:

When the user closes the lid, the laptop goes to sleep.

Versus

When the lid is closed, the laptop is asleep.

It is the same as the difference between these two implementations:

public class LaptopPowerManagerEventDriven
{
    private bool _sleeping = false;

    public LaptopPowerManagerEventDriven(LaptopLid lid)
    {
        lid.Closed += () => _sleeping = true;
        lid.Opened += () => _sleeping = false;
    }

    public bool Sleeping
    {
        get { return _sleeping; }
    }
}

Versus

public class LaptopPowerManagerDependencyDriven
{
    private LaptopLid _lid;

    public LaptopPowerManagerDependencyDriven(LaptopLid lid)
    {
        _lid = lid;
    }

    public bool IsSleeping
    {
        get { return _lid.IsClosed; }
    }
}

I don’t have any inside information regarding how OS X or Windows implement power management, but I can guess which one uses which approach.

Leave a Reply

You must be logged in to post a comment.