Design Mode - Appearance Mode

Facade Pattern - Facade Pattern

Facade Pattern : Provides a unified entry for a set of interfaces in a subsystem. The Facade pattern defines a high-level interface that makes this subsystem easier to use.

My own understanding: The facade class calls multiple subsystems, combining methods from several different classes into one method.

(1) Appearance role: the client can call its methods, and the appearance role can know the functions and responsibilities of the relevant (one or more) subsystems; under normal circumstances, it will send all messages sent from the client The request is delegated to the corresponding subsystem and passed to the corresponding subsystem object for processing.

(2) Subsystem roles: There can be one or more subsystem roles in a software system. Each subsystem may not be a separate class, but a collection of classes, which implements the functions of the subsystems; each subsystem has It can be called directly by the client, or by the appearance role, which handles requests from the appearance class; the subsystem does not know the existence of the appearance, and for the subsystem, the appearance role is just another client.


Subsystem:

class SubSystemA
{
    public void MethodA()
    {
        //Business implementation code
    }
}

class SubSystemB
{
    public void MethodB()
    {
        //Business implementation code
     }
}

class SubSystemC
{
    public void MethodC()
    {
        //Business implementation code
    }
}
Appearance

class Facade
{
    private SubSystemA obj1 = new SubSystemA();
    private SubSystemB obj2 = new SubSystemB();
    private SubSystemC obj3 = new SubSystemC();

    public void Method()
    {
        obj1.MethodA();
        obj2.MethodB();
        obj3.MethodC();
    }
}

client

class Program
{
    static void Main(string[] args)
    {
        Facade facade = new Facade();
        facade.Method();
    }
}



Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326852290&siteId=291194637