BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...
Design patterns in XPages
1. Design Patterns
The Open-Close Principle
Rob Bontekoe
XPages Meetup October 8th 2014, ‘s-Hertogenbosch
2. Introduction
Rob Bontekoe
- Java Developer at Rienks Arbodienst, XPages
Instructor at AppliGate.
The project
- Billing Manager.
- XPages, Java, Managed Beans.
Design Paterns
- a.o. Decorator Pattern, subject of this presentation.
3. ArboZorg
Core system:
- Interdisciplinairy,
- a.o. registration of billable medical records.
One basic billing type per activity/record:
- Time or
- Quantity or
- One-time price.
Maarten Teuben
4. Billing Manager - Task 1
To calculate the price per activity based on:
- Billing type,
- Standard price or Contract price,
- No-Show percentage,
- VAT (taxable and non taxable part),
- Create a modified data set.
5. Billing Manager - Task 2
To deliver the modified data set to its
subscribers. The subscriber Invoice Preparator
creates the invoice lines and the appendix:
- Aggregated invoice lines per product group.
- A detailed appendix for HR, contains sensitive personal
information and has to be destroyed by HR after
approval of the invoice.
6. Other Tasks Billing Manager
- To export the invoice lines to the accounting software
using SOAP*).
- To update the invoice lines and appendix with the
invoice number using SOAP.
- Mail appendixes.
- To present graphical information for the management.
8. How to tacle Future Extensions?
What if management wants:
- Discount option and/or
- Sliding-scale price option and/or
- Additional management information or
- Who knows what else?
Design pattern?
9. Two Patterns
Observator Pattern:
Different kind of subscribers using the same data set.
Decorator Pattern:
Easy way to dynamically extent the price calculation model.
10. OO*) - Open-Close Prinicple
Classes should be open for extension but
closed for modification.
Head First Design Patterns
“This is especially important because the application deals
with money. We don’t want to break tested and proven
code”.
Rob Bontekoe
*) Object Oriented (Programming)
11. Decorator Pattern
Also known as Wrapper Pattern,
adds behavior to an object without affecting the
behavior of other objects of the same class.
Wikipedia
13. PriceRuleType’s
PriceRulesType’s are based on the activity
property billingType and additional
conditions:
- PRICE_MINUTES_VAT
- PRICE_MINUTES_NOSHOW_VAT
- PRICE_QUANTITY_VAT
- PRICESCALE_QUANTITY_VAT (future?)
14. Composing a PriceRule
public double calculatePrice(IModifiedActivity modifiedActivity) {
PriceRule rule = null;
if (PriceRuleType.PRICE_MINUTES_VAT == modifiedActivity.getPriceRuleType()) {
rule = new Price(modifiedActivity); // Price: 75.00 per hour
rule = new Minutes(rule, modifiedActivity); // Minutes: 30
rule = new Vat(rule, modifiedActivity); // VAT: 0.21
}
// Other price rules
// Future price rules
return rule.price();
}
17. Summary
A design pattern is a general reusable and proven solution
to a commonly occuring problem within a given context.
One of the OO principles is the Open-Close Principle.
The Decorator Pattern is an attractive alternative for
subclassing.