Overloading interface buttons, what are the best practices?

Posted by XMLforDummies on Programmers See other posts from Programmers or by XMLforDummies
Published on 2012-09-06T19:32:01Z Indexed on 2012/09/06 21:50 UTC
Read the original article Hit count: 338

Imagine you'll have always a button labeled "Continue" in the same position in your app's GUI. Would you rather make a single button instance that takes different actions depending on the current state?

private State currentState = State.Step1;

private ContinueButton_Click()
{
    switch(currentState)
    {
        case State.Step1:
            DoThis();
            currentState = State.Step2;
            break;
        case State.Step2:
            DoThat();
            break;
    }
}

Or would you rather have something like this?

public Form()
{
    this.ContinueStep2Button.Visible = false;
}

private ContinueStep1Button_Click()
{
    DoThis();
    this.ContinueStep1Button.Visible = false;
    this.ContinueStep2Button.Visible = true;
}

private ContinueStep2Button_Click()
{
    DoThat();
}

© Programmers or respective owner

Related posts about design

Related posts about programming-practices