Q: What are design patterns

Slowly: Design pattern is a solution for common scenarios in system service design, which can solve common problems encountered in the development of functional logic. Design pattern is not limited to the final implementation scheme, but in this conceptual pattern, to solve the code logic problems in system design.

Q: What is appearance mode

Slowly: The facade hides the complexity of the system and provides an interface that the client can access. This design pattern is structural in that it adds an interface to an existing system to hide the complexity of the system.

Small Q: GOT it, hurry up the code.

public interface Shape {
    void draw(a);
}
Copy the code
public class Rectangle implements Shape {
    @Override
    public void draw(a) {
        System.out.println("Rectangle::draw()"); }}Copy the code
public class Square implements Shape {
    @Override
    public void draw(a) {
        System.out.println("Square::draw()"); }}Copy the code

Create a facade class

public class ShapeMaker {
    private String rectangle;
    private Shape square;
    
    public ShapeMaker(a) {
      rectangle = new Rectangle();
      square = new Square();
   }
 
   public void drawRectangle(a){
      rectangle.draw();
   }
   public void drawSquare(a){ square.draw(); }}Copy the code

Use this appearance class to draw various shapes

public class FacadePatternDemo {
   public static void main(String[] args) {
      ShapeMaker shapeMaker = newShapeMaker(); shapeMaker.drawCircle(); shapeMaker.drawRectangle(); shapeMaker.drawSquare(); }}Copy the code

Q: What’s the difference between appearance mode and adapter mode?

Slowly: The facade encapsulates complex objects and exposes a simple interface. An adapter encapsulates objects with similar functions and exposes a unified interface.