A riff on strongly typed. Used to describe an implementation that needlessly relies on strings when programmer and refactor friendly options are available. Here's stringly typed java code example:

class ExchangeRate {
	final String sourceCurrency;
	final String targetCurrency;
	final BigDecimal value;
}
class ExchangeOffice {
	BigDecimal exchange(BigDecimal amount, String sourceCurrency, String targetCurrency) {
		ExchangeRate rate = repository.findRate(sourceCurrency, targetCurrency);
		return amount * rate.value;
	}
}

Introduce a new enum, value object, or a POJO, to make the code strongly typed again:

class ExchangeRate {
	final Currency source;
	final Currency target;
	final BigDecimal value;
}
class ExchangeOffice {
	Money exchange(Money money, Currency target) {
		ExchangeRate rate = repository.findRate(money.currency, target);
		return new Money(money.amount * rate.value, target);
	}
}

Code is now a little bit easier to read, but more importantly it's easier to use. The programmer that is trying to call the exchange() method, does not have to guess which strings should he pass as parameters.

Mark Simpson, New Programming Jargon

            Votes: 0

See more like this: