views:

334

answers:

5

I have been given a programming assignment and one of the things I have to do is implement method which a wrapper method which relies on another method to sort the coordinates from lowest to highest. I am unsure on what exactly is meant by implementing a wrapper method.

static void sortCoordsByZ(double[][] coords) {
 //implement the wrapper method for the recursive sort method. all work is done the recursive sort method
}

static void recursiveSort(double[][] coords, int lo, int hi) {
 //recursive sort method
}
+1  A: 

It wraps another method :) Probably it adds some additional arguments, like initial values of lo and hi in your case and acts as an entry point to your sorting.

Dmitry
+3  A: 

A wrapper method is an adapter or a façade; it provides an alternative interface for an existing method.

You've been asked to write a façade - to provide a simpler interface for clients that don't need to specify high and low values.

Jeff Sternal
+1  A: 

When you implement a wrapper method, you are effectively coding up a variant of an existing method, usually because the existing method doesn't satisfy your current requirements. The original method may be too complicated (too many parameters), or it may not quite do the required thing, which means you have to write a wrapper (or overload) that does the extra work the original method doesn't. Usually when writing a wrapper you will still leverage the original function for whatever it does, and fill in the gaps with your wrapper.

slugster
+1  A: 

You're acting as a wrapper method right now by asking your assignment question on Stack Overflow!

A wrapper method answers a question by asking an "expert" method for the answer. Generally, it does three things:

  1. It frames the question in such a way that the "expert" method can understand it.
  2. It asks the "expert" method the question
  3. It does something easy to the answer to put it in the right format for the caller.

In your case, the "expert" method is recursiveSort(), and your sortCoordsByZ() method will have to call recursiveSort() with the right parameters, and then maybe do something with the answer before returning it.

Grandpa
+1  A: 

In that case shouldn't this be all I need to put in the "sort by z" method if its going through an array called coords that has all its slots filled?

recursiveSort(coords, 0, coords.length-1);
Shawn
Yes, that's precisely what you should do.
bcat