#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// 定义子系统A
typedef struct subsystemA {
void (*operationA)(struct subsystemA* subsystem);
} SubsystemA;
// 定义子系统B
typedef struct subsystemB {
void (*operationB)(struct subsystemB* subsystem);
} SubsystemB;
// 定义子系统C
typedef struct subsystemC {
void (*operationC)(struct subsystemC* subsystem);
} SubsystemC;
// 定义外观
typedef struct facade {
SubsystemA subsystemA;
SubsystemB subsystemB;
SubsystemC subsystemC;
void (*operation)(struct facade* facade);
} Facade;
// 实现子系统A的操作
void operationA(SubsystemA* subsystem) {
printf("SubsystemA operation.\n");
}
// 实现子系统B的操作
void operationB(SubsystemB* subsystem) {
printf("SubsystemB operation.\n");
}
// 实现子系统C的操作
void operationC(SubsystemC* subsystem) {
printf("SubsystemC operation.\n");
}
// 实现外观的操作
void operation(Facade* facade) {
facade->subsystemA.operationA(&facade->subsystemA);
facade->subsystemB.operationB(&facade->subsystemB);
facade->subsystemC.operationC(&facade->subsystemC);
}
int main(int argc, char *argv[])
{
Facade facade;
facade.subsystemA.operationA = operationA;
facade.subsystemB.operationB = operationB;
facade.subsystemC.operationC = operationC;
facade.operation = operation;
facade.operation(&facade);
return 0;
}
- ()[https://zhuanlan.zhihu.com/p/637760241]
- ()[https://blog.csdn.net/lbaihao/article/details/117820088]
- ()[https://blog.csdn.net/feixiaoxing/article/details/7100334]