Question: Imagine that youre creating a data mining application that analyzes corporate documents. Users feed the app documents in various formats (PDF, DOC, CSV), and it

Imagine that youre creating a data mining application that analyzes corporate documents. Users feed the app documents in various formats (PDF, DOC, CSV), and it tries to extract meaningful data from these docs in a uniform format. The first version of the app could work only with DOC files. In the following version, it was able to support CSV files. A month later, you taught it to extract data from PDF files. Imagine that youre creating a data mining application that analyzes corporate documents.

At some point, you noticed that all three classes have a lot of similar code. While the code for dealing with various data formats was entirely different in all classes, the code for data processing and analysis is almost identical. Wouldnt it be great to get rid of the code duplication, leaving the algorithm structure intact?

There was another problem related to client code that used these classes. It had lots of conditionals that picked a proper course of action depending on the class of the processing object. If all three processing classes had a common interface or a base class, youd be able to eliminate the conditionals in client code and use polymorphism when calling methods on a processing object.

Use the Template Method pattern to break down an algorithm into a series of steps, turn these steps into methods, and put a series of calls to these methods inside a single template method.

Code in java

\begin{tabular}{|l|} \hline DocDataMiner \\ \hline \\ \hline+ mine(path) \\ \hline \end{tabular} file = openFile(path) rawData = extractDocData(file) data = parseDocData(rawData) analysis = analyzeData(data) sendReport(analysis) \begin{tabular}{|l|} \hline CSVDataMiner \\ \hline \\ \hline mine(path) \\ \hline \end{tabular} \begin{tabular}{|l|} \hline PDFDataMiner \\ \hline \\ \hline mine(path) \\ \hline \end{tabular} closeFile(file) file = openFile(path) file = openFile(path) rawData = extractPDFData(file) data = parsePDFData(rawData) analysis = analyzeData(data) sendReport(analysis) closeFile(file) DATA

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!