Skip to content

Instantly share code, notes, and snippets.

@lazandrei19
Created November 15, 2019 06:13
Show Gist options
  • Save lazandrei19/b68613143eeda6681ba54523d85bbdb5 to your computer and use it in GitHub Desktop.
Save lazandrei19/b68613143eeda6681ba54523d85bbdb5 to your computer and use it in GitHub Desktop.

Visitor & OOP Concepts Lab

The purpose of the first and main task is to use the Visitor pattern to generate two types of formatted text, one in dokuwiki syntax, one in markdown syntax.

In the second task you need to use an API that has a visitor design. Follow the instructions from JavaFilesVisitor class.

Syntax specs

Types of text parts you need to convert:

  • Italic:
    • dokuwiki: //text//
    • markdown: text or text
  • Bold:
    • dokuwiki: text *markdown: text or text
  • External urls:

The plain text you leave as is.

Architecture of the implementation:

Entry point: * Test class, run its main * uncomment its code after you have implemented the required classes

TextSegment - these are the objects needed to be visited * ItalicTextSegment * BoldTextSegment * UrlSegment * PlainTextSegment

DocumentVisitor - the interface implemented by all the visitors applied on TextSegment objects * DokuWikiVisitor * MarkdownVisitor

WikiGenerator - applies the visitors on a collection of TextSegment objects - uses the visitors' getDocument() method to obtain the document string and a StringBuilder object

+---------------------------+ | TextSegment | +---------------------------+ | - content | +---------------------------+ +--------------------------------+ | + accept(DocumentVisitor) |------------------------------>| DocumentVisitor | +---------------------------+ +--------------------------------+ ^ | + visit(ItalicTextSegment) | | | + visit(BoldTextSegment) | | +-------------------+ | + visit(UrlSegment) | |- | ItalicTextSegment | | + visit(PlainTextSegment) | | +-------------------+ | + getDocument(): StringBuilder | | +--------------------------------+ | +-------------------+ ˆ |- | BoldTextSegment | | | +-------------------+ | +------------------+ | |-| DokuWikiVisitor | | +-------------------+ | +------------------+ |- | UrlSegment | | | +-------------------+ | +------------------+ | | - url | |-| MarkdownVisitor | | | - description | +------------------+ | +-------------------- | | +-------------------+ |- | PlainTextSegment | +-------------------+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment