Apply Template Method Pattern in Report Implementation
-
Upload
guo-albert -
Category
Documents
-
view
1.187 -
download
2
Transcript of Apply Template Method Pattern in Report Implementation
![Page 1: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/1.jpg)
Apply Template Method Pattern in Report ImplementationAlbert Guo
![Page 2: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/2.jpg)
2
Agenda Introduction Template method: UML class diagram Usage Example Benefits
![Page 3: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/3.jpg)
3
Introduction A template method defines the program skeleton of an
algorithm. One or more of the algorithm steps can be overridden by subclasses to allow differing behaviors while ensuring that the overarching algorithm is still followed.
In object-oriented programming, first a class is created that provides the basic steps of an algorithm design. These steps are implemented using abstract methods. Later on, subclasses change the abstract methods to implement real actions. Thus the general algorithm is saved in one place but the concrete steps may be changed by the subclasses.
![Page 4: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/4.jpg)
4
Introduction – cont. Intent
Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.
Motivation Sometimes you want to specify the order of
operations that a method uses, but allow subclasses to provide their own implementations of some of these operations
![Page 5: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/5.jpg)
5
Participants
CollaborationsConcreteClass relies on AbstractClass to implement the invariant steps of the algorithm.
![Page 6: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/6.jpg)
6
Participants – cont.
Abstract class Defines abstract primitive operations that concrete subclasses
define to implement steps of an algorithm. Implements a template method defining the skeleton of an
algorithm. The template method calls primitive operations as well as operations defined in AbstractClass or those of other objects.
Concrete class implements the primitive operations to carry out subclass-
specific steps of the algorithm.
![Page 7: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/7.jpg)
7
Usage Operations which must be overridden by a subclass should
be made abstract If the template method itself should not be overridden by a
subclass, it should be made final In a template method, the parent class calls the operations of
a subclass and not the other way around. This is an inverted control structure that’s sometimes referred to as "the Hollywood principle," as in, "Don't call us, we'll call you".
![Page 8: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/8.jpg)
8
Example
![Page 9: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/9.jpg)
9
Use Case Diagram
![Page 10: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/10.jpg)
10
Class Diagram
Abstract primitive operations
Template method
implement primitive operations
![Page 11: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/11.jpg)
11
Template Method Content
Get data source
Assign Jasper
Template File
Generate JasperPrint
Setup Export Format
Export Report
![Page 12: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/12.jpg)
12
Abstract primitive operations
Template method
Abstract Class
![Page 13: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/13.jpg)
13
extends abstract class
Implement operation in each method
Concrete Class
![Page 14: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/14.jpg)
14Implement operation in each methodConcrete Class
![Page 15: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/15.jpg)
15
Sequence Diagram
![Page 16: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/16.jpg)
16
NIG135Controller
it will be executed in sequence:1. prepareDataSource2. getReportTemplateFile3. generateJasperPrint4. setupExportFormat5. exportReport
![Page 17: Apply Template Method Pattern in Report Implementation](https://reader035.fdocuments.in/reader035/viewer/2022081421/555a783cd8b42abb628b459f/html5/thumbnails/17.jpg)
17
Benefits To make many similar operations template. From many specialized operations to a generalized
operation. Refactor common behavior to simplify code. Algorithm related improvement.