design patterns in xpages

18
Design Patterns The Open-Close Principle Rob Bontekoe XPages Meetup October 8th 2014, ‘s-Hertogenbosch

Upload: rob-bontekoe

Post on 05-Dec-2014

260 views

Category:

Education


7 download

DESCRIPTION

Presentation about the design patterns used in the ArboZorg Billing Manager. The focus is on de Decorator Design Pattern

TRANSCRIPT

Page 1: Design patterns in XPages

Design PatternsThe Open-Close Principle

Rob Bontekoe

XPages Meetup October 8th 2014, ‘s-Hertogenbosch

Page 2: Design patterns in XPages

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.

Page 3: Design patterns in XPages

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

ArboZorg

Page 4: Design patterns in XPages

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.

Billing Manager - Task 1

Page 5: Design patterns in XPages

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.

Billing Manager - Task 2

Page 6: Design patterns in XPages

- To export the invoice lines to the accounting softwareusing SOAP*).

- To update the invoice lines and appendix with the invoice number using SOAP.

- Mail appendixes.- To present graphical information for the management.

*) Simple Object Access Protocol - Industy standard for exchanging structured information

Other Tasks Billing Manager

Page 7: Design patterns in XPages

Screenshot Billing Manager

Page 8: Design patterns in XPages

What if management wants:- Discount option and/or- Sliding-scale price option and/or- Additional management information or- Who knows what else?

Design pattern?

How to tacle Future Extensions?

Page 9: Design patterns in XPages

Observator Pattern:Different kind of subscribers using the same data set.

Decorator Pattern:Easy way to dynamically extent the price calculation model.

Two Patterns

Page 10: Design patterns in XPages

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)

OO*) - Open-Close Prinicple

Page 11: Design patterns in XPages

Decorator Pattern

Also known as Wrapper Pattern,adds behavior to an object without affecting the behavior of other objects of the same class.Wikipedia

Page 12: Design patterns in XPages

Decorator Pattern Diagram, ArboZorg

Page 13: Design patterns in XPages

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?)

PriceRuleType’s

Page 14: Design patterns in XPages

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();}

Composing a PriceRule

Page 15: Design patterns in XPages

Wrapping the Objects

Page 16: Design patterns in XPages

Future Extensions?I’m

prepared

Page 17: Design patterns in XPages

SummaryA 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.

Page 18: Design patterns in XPages

References

Head First: Design PatternsIcons - IconExperience