Acme Travel Agency Case Study: Step 2

for RuBoard

We will now apply our knowledge of interfaces to a little restructuring of the Acme case study. A major benefit of using interfaces is that they raise the level of abstraction somewhat, helping you to understand the system by way of the interface contacts, without worrying about how the system is implemented.

As usual, our case study code is in the CaseStudy directory for this chapter.

The Contracts

There are two main sets of contracts in the Acme Travel Agency Case Study. The first specifies operations on customers, and the second, operations involving hotels.

Customer Contract

The ICustomer interface shown below specifies the methods to be used by clients in the Acme Travel Agency system.

 public interface ICustomer  {     int RegisterCustomer(string firstName, string lastName,                          string emailAddress);     void UnregisterCustomer(int id);     ArrayList GetCustomer(int id);     void ChangeEmailAddress(int id, string emailAddress);  } 

The RegisterCustomer , UnregisterCustomer , and ChangeEmailAddress method definitions are exactly the same as the methods we implemented in the Customers class. The GetCustomer method is new. Previously, we had a ShowCustomers method, which displayed a list of customers to the console. This method was strictly temporary. For general use we want to return data and let the client decide what to do with it. The GetCustomer method returns information about one or all customers in an array list. If -1 is passed for the id, the list will contain all the registered customers. Otherwise, the list will contain the customer information for the customer with the given id. If no customer has that id, the list will be empty.

Hotel Contracts

We next look at the functionality of the class HotelBroker . The methods divide fairly naturally into three groups.

  • Hotel information, such as the cities where hotels are available and the hotels within a city

  • Hotel administration, such as adding or deleting a hotel, or changing the number of rooms and rate of a hotel

  • Hotel reservations, such as booking or canceling a reservation or obtaining a list of reservations

Accordingly we create three interfaces for the HotelBroker . These interfaces are defined in AcmeDefinitions.cs .

 public interface IHotelInfo  {     ArrayList GetCities();     ArrayList GetHotels();     ArrayList GetHotels(string city);  }  public interface IHotelAdmin  {     string AddHotel(string city, string name,        int numberRooms, decimal rate);     string DeleteHotel(string city, string name);     string ChangeRooms(string city, string name,        int numberRooms, decimal rate);  }  public interface IHotelReservation  {     ReservationResult MakeReservation(int customerId,        string city, string hotel, DateTime checkinDate,        int numberDays);     void CancelReservation(int id);     ArrayList FindReservationsForCustomer(int customerId);  } 

The Implementation

We examined the Step 1 implementation of the hotel brokerage system in detail in Chapter 4. The Step 2 implementation uses collections in place of arrays, and it passes information to the client rather than displays information directly.

Structures

One detail of our implementation concerns the data structures used to pass lists to the client. We use the ArrayList class. But what do we store in each array list? We could use Customer objects and Hotel objects. The problem here is that these classes have implementation-specific data in them, as well as the information fields that the client program cares about. To obtain implementation neutral representations, we introduce several structures.

In Customers.cs we define the CustomerListItem structure for passing customer information.

 public struct CustomerListItem  {     public int CustomerId;     public string FirstName;     public string LastName;     public string EmailAddress;  } 

In AcmeDefinitions.cs we define structures for hotels, reservations, and reservation results.

 public struct HotelListItem  {     public string City;     public string HotelName;     public int NumberRooms;     public decimal Rate;  }  public struct ReservationListItem  {     public int CustomerId;     public int ReservationId;     public string HotelName;     public string City;     public DateTime ArrivalDate;     public DateTime DepartureDate;     public int NumberDays;  }  public struct ReservationResult  {     public int ReservationId;     public decimal ReservationCost;     public decimal Rate;     public string Comment;  } 

The ReservationResult returns a ReservationId of -1 if there is a problem, giving an explanation of the problem in the Comment field. Otherwise "OK" is returned in the Comment field.

We invite you to examine the code in the CaseStudy folder and to build and run the program.

for RuBoard


Application Development Using C# and .NET
Application Development Using C# and .NET
ISBN: 013093383X
EAN: 2147483647
Year: 2001
Pages: 158

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net