9.2. Designing a Program

Perhaps the most difficult task a new programmer faces is knowing where to start when designing a program. Every program is a little different, so each design must be a little different. Given that, where's the best place to start?

While it is true that programs are different, you already know that all programs have at least one thing in common: the Five Program Steps. With that in mind, let's return to the clsDates program that I mentioned at the start of the chapter. The goal of this program is to write a class that can determine the date of Easter and tell us whether the year in question is a leap year or not. Let's see how you can use the Five Program Steps as a starting point for your design.

9.2.1. The Five Program Steps

Let's assume that the user interface shown in Figure 9-1 is good enough for the program. Under that assumption, we'll examine the Five Program Steps from a design perspective.

9.2.1.1. Initialization Step

For this program, about the only thing the Initialization Step needs to do is properly initialize the objects you've placed on the frmMain form and display that form on the screen. Listing 9-3 shows the frmMain code as it currently exists after you've followed the instructions at the beginning of the chapter.

Example 9-3. Listing 9-3
using System; using System.Windows.Forms; public class frmMain : Form { private TextBox txtYear; private Button btnCalc; private Button btnClose; private Label lblLeapYearResult; private Label lblEasterResult; ...

Get Beginning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.