介绍
当不需要全部实现接口提供的方法时,可先设计一个抽象类实现接口,并为该接
口中每个方法提供一个默认实现(空方法),那么该抽象类的子类可有选择地覆
盖父类的某些方法来实现需求
接口适配器模式应用实例
/**
* @author fanxiaofeng
* @Date 2020/9/21 17:45
*/
public interface interfaceDemo {
public void open();
public void close();
public void start();
public void end();
}
public abstract class AbsAdapter implements interfaceDemo {
@Override
public void open() {
}
@Override
public void close() {
}
@Override
public void start() {
}
@Override
public void end() {
}
}
/**
* @author fanxiaofeng
* @Date 2020/9/2117:52
*/
public class Client {
public static void main(String[] args) {
AbsAdapter adapter = new AbsAdapter() {
@Override
public void open() {
super.open();
System.out.println("打开");
}
};
adapter.open();
}
}