void simulatortest(AbstractDuckFactory
duckFactory)
{
/*Quackable mallQuackable=new
MallardDuck();//定义绿头鸭
Quackable reQuackable=new RedheadDuck();//定义红头鸭
Quackable duckcall =new
DuckCall();//定义鸭鸣器
Quackable rubber=new RubberDuck();//定义橡皮鸭
*/
Quackable mallQuackable=duckFactory.createMallardDuck(); //定义绿头鸭
Quackable reQuackable=duckFactory.createRedheadDuck(); //定义红头鸭
Quackable duckcall=duckFactory.createDuackcall(); //定义鸭鸣器
Quackable rubber=duckFactory.createRubberDuck(); //定义橡皮鸭
Quackable gooseDuck= new GooseAdapter( new Goose());
System. out .println("Test
Ducksimulator" );
Flock flock= new Flock(); //首先将一群鸭子加入到flock中
,这种鸭子包含了岁有的种类
flock.add(mallQuackable);
flock.add(reQuackable);
flock.add(duckcall);
flock.add(rubber);
flock.add(gooseDuck);
//定义一群绿头鸭,仅仅含有绿头鸭
Flock flockmallard= new Flock();
Quackable mallardone=duckFactory.createMallardDuck();
Quackable mallardtwo=duckFactory.createMallardDuck();
Quackable mallardthree=duckFactory.createMallardDuck();
Quackable mallardfour=duckFactory.createMallardDuck();
Quackable mallardfive=duckFactory.createMallardDuck();
flockmallard.add(mallardone);
flockmallard.add(mallardtwo);
flockmallard.add(mallardthree);
flockmallard.add(mallardfour);
flockmallard.add(mallardfive);
//将绿头鸭群 flockmallard加入到
flock中
flock.add(flockmallard);
System. out .println("整群鸭子叫:" );
Duckquack(flock);
System. out .println("绿头鸭群叫" );
Duckquack(flockmallard);
System. out .println("The
Duck quacked " + QuackCounter.getQuacks ()+"
times");
}