System.out.println("I'm a real Mallard duck"); //我是一个真正的绿头鸭
}
}
package strategyPattern;
/**
* 绿头鸭继承鸭类
* @author wwj
*
*/
public class MallardDuck extends Duck{
/**
* 因为MallardDuck继承Duck类,所以具有flyBehavior与quackBehavior实例变量
*/
public MallardDuck() {
quackBehavior = new Quack(); //真正的呱呱叫
flyBehavior = new FlyWithWings(); //会用翅膀飞
}
public void display() {
System.out.println("I'm a real Mallard duck"); //我是一个真正的绿头鸭
}
}
[java] view plain
copy print ?
package strategyPattern;
publicclass RedheadDuck extends Duck{
public RedheadDuck() {
flyBehavior = new FlyWithWings();
quackBehavior = new Quack();
}
@Override
publicvoid display() {
System.out.println("I'm a RedheadDuck!!"); //红头鸭
}
}
package strategyPattern;
public class RedheadDuck extends Duck{
public RedheadDuck() {
flyBehavior = new FlyWithWings();
quackBehavior = new Quack();
}
@Override
public void display() {
System.out.println("I'm a RedheadDuck!!"); //红头鸭
}
}
[java] view plain
copy print ?
package strategyPattern;
publicclass RubberDuck extends Duck{
public RubberDuck() {
}
@Override
publicvoid display() {
System.out.println("I'm a RubberDuck!!!");
}
}
package strategyPattern;
public class RubberDuck extends Duck{
public RubberDuck() {
}
@Override
public void display() {
System.out.println("I'm a RubberDuck!!!");
}
}
[java] view plain
copy print ?
package strategyPattern;
publicclass ModelDuck extends Duck {
public ModelDuck() {
flyBehavior = new FlyNoWay(); //不会飞
quackBehavior = new Quack(); //会叽叽叫
}
@Override
publicvoid display() {
System.out.println("I'm a model duck");
}
}
package strategyPattern;
public class ModelDuck extends Duck {
public ModelDuck() {
flyBehavior = new FlyNoWay(); //不会飞
quackBehavior = new Quack(); //会叽叽叫
}
@Override
public void display() {
System.out.println("I'm a model duck");
}
}
[java] view plain
copy print ?
package strategyPattern;
publicclass DecoyDuck extends Duck{
public DecoyDuck(){
}
@Override
publicvoid display() {
System.out.println("I'm a DecoyDuck!!!"); //我是一只诱饵鸭
}
}
package strategyPattern;
public class DecoyDuck extends Duck{
public DecoyDuck(){
}
@Override
public void display() {
System.out.println("I'm a DecoyDuck!!!"); //我是一只诱饵鸭
}
}
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return&
在JDK1.5之前的单例实现方式有两种(懒汉式和饿汉式并无设计上的区别故看做一种),两者同是私有构
造器,导出静态成员变量,以便调用者访问。
第一种
package singleton;
public class Singleton {
//导出全局成员
public final static Singleton INSTANCE = new S