design patterns in xpages

Post on 05-Dec-2014

263 Views

Category:

Education

7 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

Design PatternsThe Open-Close Principle

Rob Bontekoe

XPages Meetup October 8th 2014, ‘s-Hertogenbosch

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.

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

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

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

- 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

Screenshot Billing Manager

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?

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

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

Two Patterns

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

Decorator Pattern

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

Decorator Pattern Diagram, ArboZorg

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

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

Wrapping the Objects

Future Extensions?I’m

prepared

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.

References

Head First: Design PatternsIcons - IconExperience

top related