????------------------------------ ????????(Iterator) -------------------------------

????(1)????????:

????????????????????????????????????????????????????????е?????????????????????????????????

???????????????first??next??previous??last??isOver??????????????????????????????.

????(2)??:

?????????????????????????.

???????: ?????????????????.

?????????: ???????????private int current=0 ; ??????????Vector???????????????????????????;???????????????.

????(3)???:

????Iterator????

????package iterator;

????public interface Iterator{

????/*

????Item:????????е???????????.???String?????????е?ITEM???String???????????????????????????????????????. --->important.

*/
public Item first();
public Item next();
public boolean isDone();
public Item currentItem();
}
Controller???????Iterator????
package iterator;
import java.util.Vector;
public class Controller implements Iterator{
private int current =0;
Vector channel;
public Controller(Vector v){
channel = v;
}
public Item first(){
current = 0;
return (Item)channel.get(current);
}
public Item next(){
current ++;
return (Item)channel.get(current);
}
public Item currentItem(){
return (Item)channel.get(current);
}
public boolean isDone(){
return current>= channel.size()-1;
}
}
Television????
package iterator;
import java.util.Vector;
public interface Television{
public Iterator createIterator();
}
HaierTV???????Television????
package iterator;
import java.util.Vector;
public class HaierTV implements Television{     ---????
private Vector channel;
public HaierTV(){
channel = new Vector();
channel.addElement(new Item("channel 1")); --????????VECTOR???
channel.addElement(new Item("channel 2"));
channel.addElement(new Item("channel 3"));
channel.addElement(new Item("channel 4"));
channel.addElement(new Item("channel 5"));
channel.addElement(new Item("channel 6"));
channel.addElement(new Item("channel 7"));
}
public Iterator createIterator(){
return new Controller(channel);          --?????VECTOR??????????й????????
}
}
Client??????
package iterator;
public class Client{
public static void main(String[] args){
Television tv = new HaierTV();
Iterator it =tv.createIterator();
System.out.println(it.first().getName());
while(!it.isDone()){
System.out.println(it.next().getName());
}
}
}
Item??????
package iterator;
public class Item{
private String name;
public Item(String aName){
name = aName;
}
public String getName(){
return name;
}
}

????------------------------------ ?????(Facade) -------------------------------

????(1)????????????????Facade???????????????????????????????????????????á?????????????????????????????????????????÷???????????????????????á?

????-->??????????????????棬???????????y?????.

????(2)?????????????????У?????????μ?????????????????????????????????????????????豭?У???о?????Щ????????????????????????????????????裬80%????貽?趼??????????????????Щ???????????????γ????????????.????????MakeACuppa()???????facade??????????????ò????????????????????????????????????ε????

public class TeaCup{.....}
public class TeaBag{.....}
public class Water{.....}
public class FacadeCuppaMaker{
private boolean TeaBagIsSteeped;
public FacadeCuppaMaker(){
System.out.println("FacadeCuppaMaker ????ó????");
}
public TeaCup makeACuppa(){
TeaCup cup = new TeaCup();
TeaBag teaBag= new TeaBag();
Water water = new Water();
cup.addFacadeTeaBag(teaBag);
water.boilFacadeWater();
cup.addFacadeWater(water);
cup.steepTeaBag();
return cup;
}
}