In this module we introduce Design Patterns, what are they, why they exist, and how to use them. We go over several examples focusing on how Design Patterns are documented, showing examples in code, and discussing advantages and disadvantages for each Design Pattern.
- Draw the UML class diagram for the Factory Method Pattern.
- Given a set of Java classes, implement the Factory Method Pattern.
- Draw the UML class diagram for the Visitor Pattern.
- Draw the UML sequence diagram for the Visitor Pattern.
- Given a set of Java classes, implement prettyPrint functionality by using the Visitor Pattern.
- Draw the UML class diagram for the Observer Pattern.
- Draw the UML sequence diagram for the Observer Pattern.
- Given a set of Java classes, implement a publish-subscribe protocol by using the Observer Pattern.
- DUE DATE: April 12th at 12:00pm (NOON)
Simple Text Document Processor Final
The HTML generation feature was very successful. The team has received a lot of comments and feature extensions from beta testers. The team has finalized the specification for the markup in the input text document and would like you to implement the specification.
HTML header
The output file should hold valid HTML. The filename passed as argument to your program becomes the
string value for the title HTML tag, e.g., passing a file named doc.txt
should generate
<title> doc.txt </title>
Paragraphs
A paragraph in the text documented is specified by a series of lines that contains text that may contain other markup separated by empty new lines. For example
This is a one line paragraph. This is a longer paragraph that contains more than one line. The paragraph *continues* until we find an empty line.
In the preceding example we have 2 paragraphs. In the HTML output paragraphs are surrounded with <p></p> HTML tags.
Headers
Headers in the text document are specified on a line on their own. The line starts with 1 or more `#` symbols. The number of `#` symbols designate the level of the header. Any header that has 6 or more `#` will be translated to a level 6 header. Following the `#` there must be a space followed by text up to the end of the line. Any markup in the text of a header is ignored and displayed verbatim in the output. The header levels in the document do not have to be in strict order, i.e., a header of level 1 can be followed by a header of level 3.
Consider the following extract
# How to confuse *and* irritate people This book covers the popular topics on how to confuse and irritate others. ### Disclaimer You will be confused, maybe irritated, by the writings in this book. Achieving both emotions is the goal of the author.
Should generate
<h1>How to confuse *and* irritate people</h1> <p>This book covers the popular topics on how to confuse and irritate others. </p> <h3>Disclaimer</h3> <p>You will be confused, maybe irritated, by the writings in this book. Achieving both emotions is the goal of the author.</p>
Blockquotes
Any line whose first character is the symbol `>` followed by a space should be indented. By adding more `>` in a sequence causes our indentation to increase the same number of times as the number of `>`. The HTML output should use the <blockquote></blockquote> tag for each instance of ``>. Here is an example fragment
Answers inline > What is the time line for the project? We are aiming for the first on June. > What are the resources allocated? > > Are you asking in terms of headcount or machines? > > > Headcount We are budgeted for 40 people.
Should generate
<p>Answers inline </p> <blockquote> <p>What is the time line for the project? </p> </blockquote> <p>We are aiming for the first on June. </p> <blockquote> <p>What are the resources allocated? </p> <blockquote> <p>Are you asking in terms of headcount or machines? </p> <blockquote> <p>Headcount</p> </blockquote> </blockquote> </blockquote> <p>We are budgeted for 40 people. </p>
Lists
We will support both numbered and bullet lists. Lists start on a line of their own. Elements of the list are designated with `1.` for number lists and `*` for bullet lists. Nesting of lists is achieved by indenting the entries of the nested list by 2 spaces. Nesting between the two types of lists is allowed. Here is an example.
Numbered list 1. one 1. two 1. inner one 1. inner two 1. inner inner one 1. inner inner two 1. inner three 1. three Bullet list * one * two * inner one * inner two * inner inner one * inner inner two * inner three * three Mixing lists 1. one 1. two * inner one * inner two 1. inner inner one 1. inner inner two * inner three 1. three 1. one 1. two * inner one * inner two 1. inner inner one 1. inner inner two * inner three 1. three
Should generate
<p>Numbered list </p> <ol> <li>one </li> <li>two <ol> <li>inner one </li> <li>inner two <ol> <li>inner inner one</li> <li>inner inner two</li> </ol> </li> <li>inner three</li> </ol> </li> <li>three </li> </ol> <p>Bullet list </p> <ul> <li>one </li> <li>two <ul> <li>inner one </li> <li>inner two <ul> <li>inner inner one</li> <li>inner inner two</li> </ul> </li> <li>inner three</li> </ul> </li> <li>three </li> </ul> <p>Mixing lists </p> <ol> <li>one </li> <li>two <ul> <li>inner one </li> <li>inner two <ol> <li>inner inner one</li> <li>inner inner two</li> </ol> </li> <li>inner three</li> </ul> </li> <li>three </li> </ol> <p>And another one </p> <ol> <li>one </li> <li>two </li> </ol> <ul> <li> inner one </li> <li> inner two </li> </ul> <ol> <li>inner inner one</li> <li>inner inner two</li> </ol> <ul> <li> inner three</li> </ul> <ol> <li>three<br> </li> </ol>
Horizontal Lines
If a line starts with 4 or more consecutive `*` followed by a new line or spaces and a new line then the HTML output should generate a horizontal line using the <hr> HTML tag. For example
This concludes our parenthetical comment on irritating behaviour. **** But we could not stop ourselves from making another parenthetical comment here ****** Nesting parenthetical arguments in written word causes confusion, or does it? ****
Should generate
<p>This concludes our parenthetical comment on irritating behaviour. </p> <hr> <p>But we could not stop ourselves from making another parenthetical comment here </p> <hr> <p>Nesting parenthetical arguments in written word causes confusion, or does it? </p> <hr>
Emphasis
The input text can contain markup to denote bold and italic text. Bold text is surrounded with `*`. Italicized text is surrounded with `_`. Emphasis markup can be used anywhere except in headers. So we can have emphasized text in the string for a list, inside blockquotes etc. For example.
So here is some *bold* text and some _italicized_ text. We can also have *_this_*, as well as well as _*this*_.
Should generate
<p>So here is some <strong>bold</strong> text and some <em>italicized</em> text. </p> <p>We can also have <strong><em>this</em></strong>, as well as <em><strong>this</strong></em></p>
Hyperlinks
The text document should allow for links. The format for specifying links wraps the text of the link using square brackets and the destination URL address using normal parenthesis, for example
You can see an example [Confused](https://media.giphy.com/media/wi9yHmX7Sztuw/giphy.gif). You can read more [here](https://en.wikipedia.org/wiki/Confusion)
Should generate
<p>You can see an example <a href="https://media.giphy.com/media/wi9yHmX7Sztuw/giphy.gif">Confused</a>. You can read more <a href="https://en.wikipedia.org/wiki/Confusion">here</a></p>
You can read more on how to create links in HTML at the W3C site.