Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

What tools might be helpful?

Answered: 1 week ago