Hello! I have a task: to break the text from the book on programming (that is, besides usually the text there are also listings), using "regular", into words, paragraph. signs, sentences, paragraphs, and so on. And it is also necessary to assemble it from these parts in its original form. Well, then make additional changes to the task. A prerequisite is the implementation of the Composite pattern. Here is the snag. However, regular expressions are clear and the pattern itself is also uncomplicated. But how to apply it here. Of course, it is clear that text elements can be both nodes (sentence, paragraph), and leaves (a word (if it is not broken into symbols), paragraph. Sign). But how to design it? Probably, there will be one interface in which there will be necessary functions for adding, deleting, receiving (which will be UnsupportedOperation for leaves), well, and some function for going through the tree (or something like that). I just can't catch up with how the pattern will simplify everything. They said that the classes in the model should decrease significantly.
Without this pattern. I would stupidly in class sentences kept an ArrayList with punctuation and words. In class Paragraph ArrayList with sentences, etc.
Can anyone understand that nonsense that I wrote? Or did anyone come across a similar application of the Composite pattern? = (Thanks in advance.