Sziasztok!
Nemrégiben dobtam fel egy olyan témát, ami az interfészekkel foglalkozott, de most tovább kell kérdeznem, mert a JAZZY nevű helyesírás ellenőrző program értelmezése során újra csak előbukkant egy ilyen probléma:
A SpellChecker osztályban található a isCorrect() függvény, ami egy szóról eldönti, hogy helyesen van leírva vagy sem. Ez így néz ki:
public boolean isCorrect(String word) {
if (userdictionary.isCorrect(word)) return true;
for (Enumeration e = dictionaries.elements(); e.hasMoreElements();) {
SpellDictionary dictionary = (SpellDictionary) e.nextElement();
if (dictionary.isCorrect(word)) return true;
}
return false;
}
Ahol a userdictionary a SpellChecker egy adattagja és így van deklarálva:
private SpellDictionary userdictionary;
A SpellDictionary pedig egy interface, ami így néz ki:
import java.util.*;
public interface SpellDictionary {
public void addWord(String word);
public boolean isCorrect(String word);
public List getSuggestions(String sourceWord, int scoreThreshold);
public List getSuggestions(String sourceWord, int scoreThreshold , int[][] matrix);
}
Kérdés: Hogyan működhet ez, hiszen az interface-ben nincs kód, csak függvénydeklarációk. Mi fut le, amikor ezt írják:
if (userdictionary.isCorrect(word)) return true;