Design Pattern:
Facade pattern hides the complexities of the system and provides an interface to the client using which the client can access the system. 模式:外观模式主要目的是隐藏系统复杂性,给客户端提供统一的入口
故事场景:
Curry
public interface Player {
//运球
void gribble();
//过人
void crossover();
//投
void shoot();
}
public class Curry implements Player {
@Override
public void gribble() {
System.out.println("1.运球过半场");
}
@Override
public void crossover() {
System.out.println("2.在半场过了欧文,詹姆斯的围堵");
}
@Override
public void shoot() {
System.out.println("3.三分出手,命中!");
}
}
外观类 用来封装复杂的业务逻辑
public class Facade {
private Player player;
public Facade(Player player){
this.player = player;
}
public void point3(){
player.gribble();
player.crossover();
player.shoot();
}
}
实验的开始
public class FacadeDemo {
public static void main(String[] args) {
Player curry = new Curry();
Facade facade = new Facade(curry);
facade.point3();
}
}
结果
