implemented accept and visit
This commit is contained in:
parent
e518460e81
commit
dcf2a95b4f
@ -14,9 +14,8 @@ public class Image implements TextComponent {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// immer diese accept methode verwenden
|
||||||
@Override
|
@Override
|
||||||
public <T> boolean accept(CountWordsVisitor<T> visitor) {
|
public <T> T accept(Visitor<T> visitor) { return visitor.visit(this); }
|
||||||
return visitor.visit(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,7 @@ public class Paragraph implements TextComponent {
|
|||||||
|
|
||||||
return wordcount;
|
return wordcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T accept(Visitor<T> visitor) { return visitor.visit(this); }
|
||||||
}
|
}
|
||||||
|
@ -20,4 +20,6 @@ public class Section implements TextComponent {
|
|||||||
return wordcount;
|
return wordcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T accept(Visitor<T> visitor) { return visitor.visit(this); }
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,5 @@ package uebung08.doc;
|
|||||||
public interface TextComponent {
|
public interface TextComponent {
|
||||||
public int countWords();
|
public int countWords();
|
||||||
|
|
||||||
public <T> boolean accept(Visitor<T> visitor);
|
public <T> T accept(Visitor<T> visitor);
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,8 @@ package uebung08.doc;
|
|||||||
|
|
||||||
public interface Visitor<T> {
|
public interface Visitor<T> {
|
||||||
T visit(TextComponent textComponent);
|
T visit(TextComponent textComponent);
|
||||||
|
T visit(Book book);
|
||||||
|
T visit(Paragraph paragraph);
|
||||||
|
T visit(Image image);
|
||||||
|
T visit(Section section);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user