public abstract class CapitalStrategy in Java

Encode Data Matrix 2d barcode in Java public abstract class CapitalStrategy
public abstract class CapitalStrategy
Making DataMatrix In Java
Using Barcode creator for Java Control to generate, create Data Matrix 2d barcode image in Java applications.
public abstract double capital(Loan loan); public double capital(Loan loan) { return riskAmountFor(loan) * duration(loan) * riskFactorFor(loan); } public abstract double riskAmountFor(Loan loan);
Barcode Generation In Java
Using Barcode generation for Java Control to generate, create bar code image in Java applications.
The capital() method is now a Template Method That completes the refactoring for theCapitalStrategyAdvisedLine and CapitalStrategyTermLoan subclasses
Read Bar Code In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
Before I handle the capital calculation in CapitalStrategyRevolver, I'd like to show what would have happened had I not created a riskAmountFor( ) method during step 1 of the refactoring In that case, I would have created a unique method for CapitalStrategyAdvisedLine's step of multiplying by loangetUnusedPercentage() I would have called such a stepunusedPercentageFor( ) and implemented it as a hook method in CapitalStrategy: public abstract class CapitalStrategy public double capital(Loan loan) { return loangetCommitment() * unusedPercentageFor(loan) * duration(loan) * riskFactorFor(loan); } public abstract double riskAmountFor(Loan loan); protected double unusedPercentageFor(Loan loan) { // hook method return 10 };
Generate DataMatrix In Visual C#
Using Barcode creator for .NET Control to generate, create DataMatrix image in .NET applications.
Because this hook method returns 10, it has no effect on calculations unless the method is overridden, as it is by CapitalStrategyAdvisedLine: public class CapitalStrategyAdvisedLine protected double unusedPercentageFor(Loan loan) { return loangetUnusedPercentage(); };
Create Data Matrix ECC200 In .NET Framework
Using Barcode printer for ASP.NET Control to generate, create Data Matrix image in ASP.NET applications.
The hook method allows CapitalStrategyTermLoan to inherit its capital( ) calculation, rather than implement ariskAmount( ) method: public class CapitalStrategyTermLoan
ECC200 Drawer In VS .NET
Using Barcode creator for .NET Control to generate, create Data Matrix image in .NET framework applications.
public double capital(Loan loan) {
Encode ECC200 In Visual Basic .NET
Using Barcode creation for VS .NET Control to generate, create Data Matrix image in .NET framework applications.
return loangetCommitment() * duration(loan) * riskFactorFor(loan);
EAN13 Creation In Java
Using Barcode generation for Java Control to generate, create EAN 13 image in Java applications.
This document was created by an unregistered ChmMagic, please go to http://wwwbisentercom to register it Thanks
Print ECC200 In Java
Using Barcode generation for Java Control to generate, create Data Matrix ECC200 image in Java applications.
protected double duration(Loan loan) { return weightedAverageDuration(loan); } private double weightedAverageDuration(Loan loan)
Paint EAN128 In Java
Using Barcode printer for Java Control to generate, create GTIN - 128 image in Java applications.
So that is another way to produce a Template Method for the capital() calculation However, it suffers from a few downsides:
Code 128 Code Set C Printer In Java
Using Barcode creation for Java Control to generate, create Code 128 Code Set B image in Java applications.
The resulting code poorly communicates the risk-adjusted capital formula (Risk Amount x Duration x Risk Factor) Two of the three CapitalStrategy subclasses, CapitalStrategyTermLoan and, as we'll see,CapitalStrategyRevolver, inherit the hook method's do-nothing behavior, which, because it is a unique step in CapitalStrategyAdvisedLine, really belongs exclusively in that class Now let's see how CapitalStrategyRevolver would take advantage of the new capital() Template Method Its original capital() method looks like this: public class CapitalStrategyRevolver public double capital(Loan loan) { return (loanoutstandingRiskAmount() * duration(loan) * riskFactorFor(loan)) + (loanunusedRiskAmount() * duration(loan) * unusedRiskFactor(loan)); }
Code 3/9 Printer In Java
Using Barcode generator for Java Control to generate, create USS Code 39 image in Java applications.
The first half of the formula resembles the general formula, Risk Amount x Duration x Risk Factor The second half of the formula is similar, but it's dealing with the unused portion of a loan We can refactor this code to take advantage of the Template Method as follows: public class CapitalStrategyRevolver public double capital(Loan loan) { return
UPCE Encoder In Java
Using Barcode printer for Java Control to generate, create UPCE image in Java applications.
supercapital(loan)
Bar Code Scanner In .NET Framework
Using Barcode decoder for VS .NET Control to read, scan read, scan image in .NET applications.
+ (loanunusedRiskAmount() * duration(loan) * unusedRiskFactor(loan)); }
Barcode Creation In C#.NET
Using Barcode creator for .NET Control to generate, create barcode image in .NET framework applications.
protected double riskAmountFor(Loan loan) { return loanoutstandingRiskAmount(); }
Bar Code Drawer In .NET Framework
Using Barcode creation for Visual Studio .NET Control to generate, create bar code image in VS .NET applications.
You could argue whether this new implmentation is easier to understand than the previous one Certainly some duplication in the formula has been removed Yet is the resulting formula easier to follow I think so, because it communicates that capital is calculated according to the general formula with the addition of unused capital The addition of unused capital can be made clearer by applying Extract Method [F] on capital(): public class CapitalStrategyRevolver public double capital(Loan loan) { return supercapital(loan)
DataMatrix Generation In .NET Framework
Using Barcode encoder for ASP.NET Control to generate, create DataMatrix image in ASP.NET applications.
+ unusedCapital(loan);
Data Matrix ECC200 Recognizer In VS .NET
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
public double unusedCapital(Loan loan) {
Paint Bar Code In Visual Basic .NET
Using Barcode encoder for .NET framework Control to generate, create barcode image in .NET applications.
This document was created by an unregistered ChmMagic, please go to http://wwwbisentercom to register it Thanks
Paint Bar Code In Visual Studio .NET
Using Barcode maker for ASP.NET Control to generate, create bar code image in ASP.NET applications.
return loanunusedRiskAmount() * duration(loan) * unusedRiskFactor(loan); }
Amazon
This document was created by an unregistered ChmMagic, please go to http://wwwbisentercom to register it Thanks
Prev
don't be afraid of buying books
Next
Extract Composite
Subclasses in a hierarchy implement the same Composite
Extract a superclass that implements the Composite
[View full size image]
This document was created by an unregistered ChmMagic, please go to http://wwwbisentercom to register it Thanks
Motivation
In Extract Superclass [F], Martin Fowler explains that if you have two or more classes with similar features, it makes sense to move the common features to a superclass This refactoring is similar: it addresses the case when the similar feature is a Composite [DP] that would
This document was created by an unregistered ChmMagic, please go to http://wwwbisentercom to register it Thanks
be better off in a superclass Subclasses in hierarchies that store collections of children and have methods for reporting information about those children are common When the children being collected happen to be classes in the same hierarchy, there's a good chance that much duplicate code can be removed by refactoring to Composite Removing such duplication can greatly simplify subclasses On one project, I found that people were confused about how to add new behavior to the system, and much of the confusion stemmed from the complex, child-handling logic propagated in numerous subclasses By applying Extract Composite, subclass code became simple, which made it easier for folks to understand how to write new subclasses In addition, the very existence of a superclass named to express that it handled Composites communicated to developers that some rich functionality could be inherited via subclassing This refactoring and Extract Superclass [F] are essentially the same I apply this refactoring when I'm only concerned with pulling up common child-handling logic to a superclass Following that, if there is still more behavior that can be pulled up to a superclass but isn't related to the Composite, I apply the pull-up logic in Extract Superclass