implemented accept and visit

This commit is contained in:
Johannes Schmelz 2024-06-08 12:14:16 +00:00
parent e518460e81
commit dcf2a95b4f
5 changed files with 12 additions and 4 deletions

View File

@ -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);
}
} }

View File

@ -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); }
} }

View File

@ -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); }
} }

View File

@ -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);
} }

View File

@ -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);
} }