Java Reference
In-Depth Information
Figure 23.2. Implementations of the Advisor interface provide the strategic
recommend() operation, relying on off-the-shelf engines.
To provide a strategy for a client, you can pass it a particular implementation of the Advisor
interface. Interfaces can define only instance methods, so GroupAdvisor and
ItemAdvisor must be instantiated to support the Advisor interface. However, only one
such object is ever necessary, and so these classes define publicly accessible singletons.
The advisor classes translate calls to recommend() into the interfaces that the underlying
engines require. For example, the GroupAdvisor class translates calls to recommend()
into the advise() interface that the Rel8 engine requires:
public Firework recommend(Customer c)
{
return (Firework) Rel8.advise(c);
}
CHALLENGE 23.1
In addition to S INGLETON and S TRATEGY , what pattern appears in
the GroupAdvisor and ItemAdvisor classes?
Search WWH ::




Custom Search