Design Patterns Java™ Workbook

(Michael S) #1
Appendix B. Solutions

Strategy (Chapter 23)................................................................................................................................


SOLUTION 23.1....................................................................................................................................


The GroupAdvisor and ItemAdvisor classes are instances of ADAPTER, providing
the interface a client expects, using the services of a class with a different interface.


SOLUTION 23.2....................................................................................................................................


Figure B.26 shows one solution.


Figure B.26. The advertising policy at Oozinoz includes four strategies that appear as four
implementations of the Advisor interface.

SOLUTION 23.3....................................................................................................................................


The code for ItemAdvisor.java should look something like:


package com.oozinoz.recommend;
import com.oozinoz.fireworks.*;
public class ItemAdvisor implements Advisor
{
public static final ItemAdvisor singleton =
new ItemAdvisor();
private ItemAdvisor() {}

Free download pdf