Home > Articles > Programming > C#

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

The Final Application

The program loads a list of food prices into a list box on startup.

 private void loadFoodTable() { 
    Foods fods =new Foods(db); 
    while (fods.hasMoreElements()){ 

And it displays the prices of the selected food when you click on it.

 private void lsFoods_SelectedIndexChanged(object sender, 
       System.EventArgs e) { 
    string food = lsFoods.Text; 
    DataTable dtable = prc.getPrices(food); 
    foreach (DataRow rw in dtable.Rows) { 
      lsPrices.Items.Add(rw["StoreName"].ToString().Trim() + 
       "\t" + rw["Price"].ToString()); 

The final program was shown in Figure 18-1.

What Constitutes the Façade?

The Façade in this case wraps the classes as follows.

  • DBase

    Contains OleDbConnection, Database, DataTable, OleDbAdapter, DataSets

  • DBTable

    Contains DataSet, DataRow, DataTable, OleDbConnection, OleDbCommandBuilder

You can quickly see the advantage of the Façade approach when dealing with such complicated data objects. This is illustrated in Figure 18-2.

Figure 18-2Figure 18-2. Façades wrapping classes make up the DBase and DBTable classes.

Consequences of the Façade

The Façade pattern shields clients from complex subsystem components and provides a simpler programming interface for the general user. However, it does not prevent the advanced user from going to the deeper, more complex classes when necessary.

In addition, the Façade allows you to make changes in the underlying subsystems without requiring changes in the client code and reduces compilation dependencies.

Thought Question

Suppose you had written a program with a File | Open menu, a text field, and some buttons controlling font (bold and italic). Now suppose that you need to have this program run from a line command with arguments. Suggest how to use a Façade pattern.

Program on the CD-ROM

C# Database Façade Classes


  • + Share This
  • 🔖 Save To Your Account