1、概述
有些人可能炒过股票,但其实大部分人都不太懂,这种没有足够了解证券知识的情况下做股票是很容易亏钱的,刚开始炒股肯定都会想,如果有个懂行的帮帮手就好,其实基金就是个好帮手,支付宝里就有许多的基金,它将投资者分散的资金集中起来,交由专业的经理人进行管理,投资于股票、债券、外汇
等领域,而基金投资的收益归持有者所有,管理机构收取一定比例的托管管理费用。
定义:
外观模式又名门面模式,是一种通过为多个复杂的子系统提供一个一致的接口,而使这些子系统更加容易被访问的模式。该模式对外有一个统一接口,外部应用程序不用关心内部子系统的具体的细节这样会大大降
低应用程序的复杂度,提高了程序的可维护性。
外观(Facade)模式是“迪米特法则”的典型应用
2、结构
外观(Facade)模式包含以下主要角色:
外观(Facade)角色:为多个子系统对外提供一个共同的接口。
子系统(Sub System)角色:实现系统的部分功能,客户可以通过外观角色访问它。
public class Light {
public void on(){
System.out.println("打开了灯...");
}
public void off(){
System.out.println("关闭了灯...");
}
}
public class Tv {
public void on(){
System.out.println("打开了电视...");
}
public void off(){
System.out.println("关闭了电视...");
}
}
public class AirCondition {
public void on(){
System.out.println("打开了空调..");
}
public void off(){
System.out.println("关闭了空调...");
}
}
//智能小度(外观类 统一接口)
public class SmartAppliancesFacade {
//组合
private Light light;
private Tv tv;
private AirCondition airCondition;
public SmartAppliancesFacade(){
light=new Light();
tv=new Tv();
airCondition=new AirCondition();
}
public void say(String message){
if (message.contains("打开")){
//一键打开
on();
}else if (message.contains("关闭")){
//一键关闭
off();
}else {
System.out.println("我听不懂你说啥");
}
}
private void off() {
light.off();
tv.off();
airCondition.off();
}
private void on() {
light.on();
tv.on();
airCondition.on();
}
}
public class Client {
public static void main(String[] args) {
SmartAppliancesFacade smartAppliancesFacade=new SmartAppliancesFacade();
smartAppliancesFacade.say("打开家电");
System.out.println("======================");
smartAppliancesFacade.say("关闭家电....");
}
}