Form Template Method

You have two methods in subclasses that perform similar steps in the same order, yet the steps are different.

Get the steps into methods with the same signature, so that the original methods become the same. Then you can pull them up.

image/svg+xml Site ResidentialSite getBillableAmount LifelineSite getBillableAmount double base = _units * _rate * 0.5;double tax = base * Site.TAX_RATE * 0.2;return base + tax; double base = _units * _rate;double tax = base * Site.TAX_RATE;return base + tax; Site getBillableAmountgetBaseAmountgetTaxAmount ResidentialSite getBaseAmountgetTaxAmount LifelineSite getBaseAmountgetTaxAmount return getBaseAmount() + getTaxAmount();