First, Design the Interface

I'm going to write a subroutine that will replace the repeated code. First, I decide how get_data_count() and print_data_count() will each call the new subroutine:

    sub get_data_count {
        my $self = shift;
        _count_engine($self);
    }
    sub print_data_count {
        my $self = shift;
        print 'Current data count:  ', _count_engine($self), "\n";
    }

In other words, I design the interface to the new subroutine even before I write its code. Note how much more readable these subroutines have become.

Previous Back to start of show Next
Slide: 13 design_interface © 2003 James E. Keenan