14. Facade mode of interface isolation mode (facade mode/appearance mode)

Interface isolation mode:

  • In the process of component construction, direct dependencies between certain interfaces often cause many problems, or even cannot be realized at all. It is a common solution to add a layer of indirect (stable) interfaces to isolate interfaces that are closely related to each other
  • typical pattern
    • Facade
    • Proxy
    • Adapter
    • Mediator 

1. Introduction to Facade

For example, in the data access system, data access will involve many objects, such as connection objects, command objects, data tables, and parameter objects. . . If you don’t impose constraints and don’t consider any design, it’s easy to write a scheme like A. The external use object is directly coupled with the internal command object, data table, etc., and subsequent internal modifications will also directly affect to the outside.

2. Motivation

  • The problem with the above scheme A is that there is too much coupling between the client of the component and various complex subsystems in the component. With the evolution of external client programs and subprograms, this excessive coupling faces many changing challenges
  • How to simplify the interaction interface between external client program and system? How to decouple the dependencies between the evolution of external client programs and the changes of internal subsystems?

3. Schema definition

        To provide a consistent (stable) interface for a set of interfaces in the system, the Facade pattern defines a high-level interface that makes this subsystem easier to use (reuse)

4. Structure

Facade mode has no fixed code structure, it is just a design idea.

 5. Summary

  • From the perspective of the client program, the Facade mode simplifies the interface of the entire component system. For the internal component and the external client program, it achieves a decoupling effect---the change of the internal subsystem will not affect the Facade. Interface changes.
  • The Facade mode pays more attention to the whole system from the level of the architecture, rather than the level of a single class. The Facade mode is more of an architectural design mode.
  • The Facade pattern is not a container, and any number of objects can be placed arbitrarily. The interior of the components in the Facade mode should be "a series of components with a relatively large mutual coupling relationship", rather than a simple collection of functions.

Guess you like

Origin blog.csdn.net/bocai1215/article/details/127585976