I am in AP Computer Science, and in there is a marine biology simulation we have to familiarize ourselves with for the AP exam. I was looking through my book, reading about interfaces, and realized "why use them?"
They seem to be just a way of further organizing things. here is an example, straight from the book:
//Represents the interface for an object that can be assigned an explicit complexity
public interface Complexity
{
public void setComplexity (int complexity);
public int get Complexity();
}
Now, here is the class that uses these methods:
public class Question implements Complexity
{
private String question, answer;
private int complexityLevel;
//Sets up the question with a default complexity
//(the constructor, I know)
public Question (String query, String result)
{
question = query;
answer = result;
complexityLevel = 1;
}
//sets the complexity level for this question
public void setComplexity (int level)
{
complexityLevel = level;
}
//Returns complexity
public int getComplexity()
{
return complexityLevel;
}
It goes on after that, but this is the implementation of the interface. What is the point of having an little blueprint for the methods if you put all the code and crap in the actual class anyway? Am I missing something? Is there some hidden use that I haven''t learned yet?