You can think of an application programming interface (API) as a contract. It specifies the way objects interact with each other.
In order to illustrate what an API is, consider the interface Dictionary
:
public interface Dictionary {
List<String> loadWords();
}
The interface Dictionary
establish the contract (API) that all dictionary implementations have to follow. Two examples of dictionaries implementation could be:
public class TextFileDictionary implements Dictionary {
public List<String> loadWords() {
// load words from a text file and return them
return words;
}
}
public class DatabaseDictionary implements Dictionary {
public List<String> loadWords() {
// load words from database and return them
return words;
}
}
Let's take now your PointSET
class as an example. As you can see, it has a bunch of methods that define the behavior of an object of the type PointSET
.
public class PointSET {
// private ... <- your data structure goes here.
public PointSET() {}
public boolean isEmpty() {}
public int size() {}
public void insert(Point2D p) {}
public boolean contains(Point2D p) {}
public Collection<Point2D> range(RectHV rect) {}
public Point2D nearest(Point2D p) {}
}
As @alexBrand pointed out, a good starting point is to define your data structure. In your case, the obvious choice is a BST. Then, in order to be coherent with the provided API, you are going to have to manipulate your data structure(s) to implement the expected behavior of PointSET
.