Decorator And Strategy Patterns Case Study

1709 Words 7 Pages
Aritra Chatterjee
Assignment #9 – Design patterns
Date: Nov. 11, 2017 Compare and contrast the use of Decorator and
Strategy patterns in two practical scenarios
Introduction
Decorator pattern – “Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality” [1]. Decorators are transparent to the component they are decorating, that is, they allow augmenting the existing functionality of a component at runtime, without necessarily letting the component know of its decorators. Decorators must conform to the interface of the component that they intend to decorate. Strategy pattern – “Define a family of algorithms, encapsulate each one, and make them
…show more content…
There are no restrictions on the interface of a strategy.
In this paper, two practical scenarios will be discussed, with each focusing on the strengths and weaknesses of the design patterns above.

Scenario – Analytics on streaming data
Problem Statement
An application needs to perform risk analysis on streaming credit card data. Some of the analyses are implemented in-house, while others are implemented at the client site based on specific client needs. In-house analytics include vendor patented outlier detection and anomaly detection algorithms. Client site implementations involve a large set of compliance rules. The in-house analytics is obfuscated and packaged into archives, with only abstract classes available for extensions. The client implementation team can use these abstract classes to provide extensions, but they are not allowed to modify the packaged archives in any way. On running a single credit card transaction through these various analytic components, a unified risk score is generated for

1

Aritra Chatterjee
Assignment #9 – Design patterns
Date: Nov. 11, 2017 that transaction. Also, a break-up of the scores contributed by individual components needs to
…show more content…
11, 2017 Scenario – PDF parsers
An application needs to be developed for parsing PDFs, and potentially performing optical character recognition (OCR) in case of non-searchable PDFs. For searchable PDFs, an open source tool called Apache PDFBox is available, while for non-searchable PDFs, depending on quality requirements, OCR needs to be performed by going to a paid Google Vision API or using open-source tools like Tesseract. A strategy pattern based solution

Figure 3 - Strategy pattern based parser
The application provides a PdfProcessor class that decides at runtime about the necessary characteristics of the PDF document, and accordingly allows for choosing a strategy implementation. At a time, only one parser strategy can be used. The policy for choosing a parser does not overlap in terms of functionality with one another. For example, if a PDF contains searchable content, PDFBox is used, which is open-source and comes at no cost to the client. If the PDF source is reliable, and comes from a high-quality image provider, Tesseract is used, as it’s again open-source, and provides pretty good results with good quality images. Only for

5

Aritra Chatterjee
Assignment #9 – Design

Related Documents