Java Application Architecture

Modularity Patterns with Examples Using OSGi

Category: Uncategorized

Foreword by Uncle Bob

I’m dancing! By god I’m dancing on the walls. I’m dancing on the ceiling. I’m ecstatic. I’m overjoyed. I’m really, really pleased.
“Why?” you ask. Well, I’ll tell you why — since you asked. I’m happy because somebody finally read John Lakos’ book!
Way back in the ‘90s, John Lakos [...]

Chapter 18 – OSGi and Groovy

package com.extensiblejava.calculator.groovy

import com.extensiblejava.loan.*

class MinimumPaymentScheduleCalculator implements LoanCalculator {
def paymentFactory

MinimumPaymentScheduleCalculator(pFactory) {
paymentFactory = pFactory
}

def Loan calculateLoan(BigDecimal presentValue, BigDecimal rate, int term) {

println("—** IN GROOVY CALCULATOR **—")

def cumulativePrincipal = new BigDecimal("0.00")
def cumulativeInterest = new BigDecimal("0.00")

def paymentSchedule = paymentFactory.createPaymentSchedule()
def adjustedRate = (rate / (new BigDecimal("1200")).setScale(2, BigDecimal.ROUND_HALF_UP))
def calculator = new MonthlyPaymentCalculator()
def monthlyPayment = calculator.calculatePayment(presentValue, rate, term)

def loanBalance = new BigDecimal(presentValue)

while (loanBalance.doubleValue() [...]

Chapter 17 – OSGi and Scala

package com.extensiblejava.calculator.scala

import com.extensiblejava.loan._
//import MonthlyPaymentCalculator._

class MinimumPaymentScheduleCalculator(paymentFactory:PaymentFactory) extends LoanCalculator {
def calculateLoan(value:java.math.BigDecimal, rate:java.math.BigDecimal, term:Int): Loan = {

Console.println("—** IN SCALA CALCULATOR **—")
val mc = new java.math.MathContext(2, java.math.RoundingMode.HALF_UP)
val presentValue = BigDecimal(value)
val presentRate = BigDecimal(rate).apply(mc)

var cumulativePrincipal = BigDecimal("0.00")
var cumulativeInterest = BigDecimal("0.00")

val paymentSchedule = paymentFactory.createPaymentSchedule()
val adjustedRate = (presentRate / (BigDecimal("1200")).setScale(2, BigDecimal.RoundingMode.HALF_UP))
val calculator = new MonthlyPaymentCalculator()
val monthlyPayment = calculator.calculatePayment(presentValue, presentRate, term)

var loanBalance = [...]

Chapter 14 – Introducing OSGi

14.1 – Introduction
The OSGi Service Platform is a standard dynamic module system for the Java platform. The OSGi Alliance developed and now manages that standard.  The specification is mature and stable, and most application platforms now allow enterprise developers to leverage OSGi in building their own enterprise applications.
A foundation of the OSGi Service Platform is the [...]

Default Implementation

For the full description, implementation variations, consequences, and detailed sample, see Page 150 in Java Application Architecture.
Statement
Provide modules with a default implementation.
Description
To maximize reuse, a module must be flexible enough so that it can function in variety of different operating environments. Yet, for a module to be usable, it must be independently deployable. To address [...]

SOLID Principles of Class Design

The SOLID principles lie at the heart of the object-oriented paradigm. Many of the principles presented here first appeared in Robert Martin’s Design Principles and Design Principles [MARTIN2000], which serves as an excellent complement to this discussion. These principles help you manage dependencies between classes and encourage class cohesion. They are also critical to effective [...]

Sample Code

This is just some sample code…
public class HelloWorld{
public static void main(String args[]) {
System.out.println("Hello World");
}
}
Do you like it?