外观模式的本质:
封装交互,简化调用
package com;
public interface AModelApi {
void testA();
}
package com.impl;
import com.AModelApi;
public class AModelImpl implements AModelApi {
@Override
public void testA() {
System.out.println("现在在A模块里操作testA方法");
}
}
package com;
public interface BModelApi {
void testB();
}
package com.impl;
import com.BModelApi;
public class BModelImpl implements BModelApi {
@Override
public void testB() {
System.out.println("现在在B模块里操作testB方法");
}
}
package com;
public interface CModelApi {
void testC();
}
package com.impl;
import com.CModelApi;
public class CModelImpl implements CModelApi {
@Override
public void testC() {
System.out.println("现在在C模块里操作testC方法");
}
}
package com;
import com.impl.AModelImpl;
import com.impl.BModelImpl;
import com.impl.CModelImpl;
public class Facade {
public void testO(){
AModelApi a = new AModelImpl();
a.testA();
BModelApi b = new BModelImpl();
b.testB();
CModelApi c = new CModelImpl();
c.testC();
}
}
import com.Facade;
public class Client {
public static void main(String[] args) {
new Facade().testO();
}
}
对设计原则的体现:最少知识原则。