Quick Index
Discussion


An method menu is a menu listing of method headers for a specific object type. Note that it is not a code listing, but a method header listing (with helpful comments).

Pretend we are visiting "Esi's Gourmet Plantain Restaurant". We would receive a menu of delectable entrees.

Similarly, when we use a given object type (e.g., City, Rectangle, etc) we are provided a helpful method menu which lists methods we can call.

Thus we want to be experts at working with method menus so that we achieve code reuse, not reinvention.

Example


Example 1: City
On the right is shown a snippet of the method menu for a City object type.

From just the method menu we can easily infer usage:

var city;
city = City.fromNameCountryLatLong(
	"Accra", "Ghana", 5.6037, -0.1870);
println(city.toString());
println(city.isInNorthernHemisphere());

-- Method Menu for City --

/**
 * Returns new City object with passed name,
 * country, lat and long values
*/
static fromNameCountryLatLong(name, country, lat, lon)

/** Returns true if this location is in the southern hemisphere */
isInSouthernHemisphere()

/** Returns nice display string for this City */
toString()

/** Returns country city is located in */
getCountry()
Example 2: Rectangle
On the right is shown a snippet of the method menu for a Rectangle object type.

From just the method menu we can easily infer usage:

var city;
city = Rectangle.fromWidthHeight(10, 5);
println('Area: ' + city.getArea());
println('Perimeter: ' + city.getPerimeter());

-- Method Menu for Rectangle --

/**
 * Returns new Rectangle with width and height set to passed
 * method params, left and top are set to 0
*/
static fromWidthHeight(w, h)

/** Returns area of rectangle */
getArea()

/** Returns perimeter of rectangle */
getPerimeter()


Method Menus in Language Libraries


We'll use Java as an example.

Java calls its method menus "method summaries".

Examples from the Java library:


Note that the method summary is for an object type. In Java, this may be an interface (like List), or a class (like String).