Random Musings

June 14, 2009

Interface example in the real world

Filed under: Book Review — haditeo @ 4:05 pm
Tags: ,

Today, i discovered a book titled “Interface-Oriented Design” published by The Pragmatic-Programmers series, when i made a trip to the local library here.

The sample PizzaOrdering interface at chapter 1 made me interesting. The interface concept is described clearly in day-to-day daily scenario.

Here are the sample discussion when you’re ordering Pizza :

Waiter : “Yo”
Me : “I would like to order order large pizza”
Waiter : “What topping do you want ?”
Me : “Cheese with pepperoni”
Waiter : “Where is your address ?”
Me : “1 Oak Street”
Waiter : “Please wait 30 minutes for your order. Thanks”

Imagine that this conversation is actually similar to most of the pizza restaurant. When it’s translated to the interface, it looks like this

public interface IPizzaOrder
{
  public interface enum Size {Small, Medium, Large};
  public interface string Topping {get; set;}
  public interface string Address {get; set;}
  public interface DateTime RetrieveEstimatedTimeCompletion();
}

Imagine that restaurant A just need to implement the IPizzaOrder interface in order to “open” a pizza restaurant. Restaurant B also. Clients / customers just need to “set” the proper attributes, such as “Size”, “Topping”, “Address” and finally invoked the RetrieveEstimatedTimeCompletion method in order to know how long is it taking to receive the pizza.

Create a free website or blog at WordPress.com.