Home  >  Article  >  Java  >  What are the advantages of java facade pattern

What are the advantages of java facade pattern

WBOY
WBOYforward
2023-05-19 19:01:041162browse

1. Reduce system interdependence. If facade mode is not used, external access will go directly into the subsystem.

This is a strong coupling relationship, which is unacceptable in system design. The output of the facade pattern solves this problem very well. All dependencies are on the facade object and have nothing to do with the subsystem.

2. Improved flexibility. Dependencies are reduced and flexibility is naturally increased.

3. Improve security. If you want to access the subsystem's business, open those logics. If you don't open the method on the facade, you can't access it.

Example

package com.sl.demo.facade;
/**
 * 电脑(门面角色)
 * @author pengkun
 *
 */
public class Computer {
//包含子系统
private CPU cpu;
private GraphicsCard graphicsCard;
private Memory memory;
public Computer() {
super();
this.cpu =new CPU();
this.graphicsCard = new GraphicsCard();
this.memory = new Memory();
}
//开启
public void start() {
System.out.println("电脑开启了。。。。");
cpu.start();
graphicsCard.start();
memory.start();
}
//关闭
public void stop() {
System.out.println("电脑关闭了。。。。");
cpu.stop();
graphicsCard.stop();
memory.stop();
}
}

The above is the detailed content of What are the advantages of java facade pattern. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete