定义：对扩展开放，对修改关闭以输入法更换皮肤为例抽象皮肤类public abstract class AbstractSkin { /** * 显示方法 */ public abstract void display(); } 默认皮肤public class DefaultSkin extends AbstractSkin { @Override public void display() { System.out.println("默认皮肤"); } }自定义皮肤public class TestSkin extends AbstractSkin { @Override public void display() { System.out.println("测试皮肤"); } } 搜狗输入法public class SouGouInput { private AbstractSkin skin; public void setSkin(AbstractSkin skin) { this.skin = skin; } public void display() { skin.display(); } }测试public class Client { public static void main(String[] args) { //1.创建输入法对象 SouGouInput input = new SouGouInput(); //2.创建默认皮肤对象 //DefaultSkin skin = new DefaultSkin(); TestSkin skin = new TestSkin(); //3.将皮肤设置到输入法中 input.setSkin(skin); //4.显示皮肤 input.display(); } }