Home > Java > javaTutorial > body text

What are the advantages of java facade pattern

WBOY
Release: 2023-05-19 19:01:04
forward
1161 people have browsed it

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();
}
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template