适配器:
适配者:
模式结构:
适配器模式包括如下角色:
实例:
public interface Robot
{
public void cry();
public void move();
}
public class Bird
{
public void tweedle()
{
System.out.println("鸟儿叽叽叫!");
}
public void fly()
{
System.out.println("鸟儿快快飞!");
}
}
public class BirdAdapter extends Bird implements Robot
{
public void cry()
{
System.out.print("机器人模仿:");
super.tweedle();
}
public void move()
{
System.out.print("机器人模仿:");
super.fly();
}
}
客户端:
public class Client
{
public static void main(String args[])
{
Robot robot=(Robot)XMLUtil.getBean();
robot.cry();
robot.move();
}
}
适配器模式适用情况: