Java Reference
In-Depth Information
SOLUTION 16.5
If you take the leap of faith that the static method
isAgencyUp()
accurately reflects reality,
the code for
createCreditCheck()
is simple:
public static CreditCheck createCreditCheck()
{
if (isAgencyUp())
{
return new CreditCheckOnline();
}
else
{
return new CreditCheckOffline();
}
}
SOLUTION 16.6
Figure B.20 shows a reasonable diagram for the
Machine
/
MachinePlanner
parallel
hierarchy. This diagram indicates that subclasses of
MachinePlanner
must implement
the method
getAvailable()
. The diagram also depicts
MachinePlanner
as an abstract
class. Alternatively, you might make
Ma-chinePlanner
concrete, letting it take the role of
the
BasicPlanner
class.
Figure B.20. Planning logic is now in a separate hierarchy. Each subclass of
Machine
knows which planner to instantiate in response to a createPlanner() call.