[实验任务一]:双向适配器
实现一个双向适配器,使得猫可以学狗叫,狗可以学猫抓老鼠。
实验要求:
1.画出对应的类图;
2.提交源代码;
package test8; public class Adapter implements Cat,Dog{ private Cat cat=new Realcat(); private Dog dog=new Realdog(); public void setcat(Cat _cat){ cat=_cat; } public void setdog(Dog _dog){ dog=_dog; } public void zhua(){} public void wang(){} public void run(){ System.out.println("小狗学小猫:"); cat.zhua(); } public void cry(){ System.out.println("小猫学小狗:"); dog.wang(); } }