设计模式之美学习-结构型-门面模式(二十三)
说明
要求一个子系统的外部与其内部的通信必须通过一个统一的对象进行。门面模式提供一个高层次的接口,使得子系统更易于使用。最核心的目的:简化子系统,简化客户使用,屏蔽多个子系统
比如 跨领域调用编排复杂逻辑,或者跨领域跨系统依赖各种api
再或者跨服务调用的Adapter防腐层
源码中的应用
flowable
ProcessEngineImpl
/** * 门面 */ public class ProcessEngineImpl implements ProcessEngine { private static final Logger LOGGER = LoggerFactory.getLogger(ProcessEngineImpl.class); protected String name; protected RepositoryService repositoryService; protected RuntimeService runtimeService; protected HistoryService historicDataService; protected IdentityService identityService; protected TaskService taskService; protected FormService formService; protected ManagementService managementService; protected DynamicBpmnService dynamicBpmnService; protected AsyncExecutor asyncExecutor; protected AsyncExecutor asyncHistoryExecutor; protected CommandExecutor commandExecutor; protected Map<Class<?>, SessionFactory> sessionFactories; protected TransactionContextFactory transactionContextFactory; protected ProcessEngineConfigurationImpl processEngineConfiguration; public ProcessEngineImpl(ProcessEngineConfigurationImpl processEngineConfiguration) { this.processEngineConfiguration = processEngineConfiguration; this.name = processEngineConfiguration.getEngineName(); this.repositoryService = processEngineConfiguration.getRepositoryService(); this.runtimeService = processEngineConfiguration.getRuntimeService(); this.historicDataService = processEngineConfiguration.getHistoryService(); this.identityService = processEngineConfiguration.getIdentityService(); this.taskService = processEngineConfiguration.getTaskService(); this.formService = processEngineConfiguration.getFormService(); this.managementService = processEngineConfiguration.getManagementService(); this.dynamicBpmnService = processEngineConfiguration.getDynamicBpmnService(); this.asyncExecutor = processEngineConfiguration.getAsyncExecutor(); this.asyncHistoryExecutor = processEngineConfiguration.getAsyncHistoryExecutor(); this.commandExecutor = processEngineConfiguration.getCommandExecutor(); this.sessionFactories = processEngineConfiguration.getSessionFactories(); this.transactionContextFactory = processEngineConfiguration.getTransactionContextFactory(); if (processEngineConfiguration.isUsingRelationalDatabase() && processEngineConfiguration.getDatabaseSchemaUpdate() != null) { this.commandExecutor.execute(processEngineConfiguration.getSchemaCommandConfig(), new SchemaOperationsProcessEngineBuild()); } if (this.name == null) { LOGGER.info("default ProcessEngine created"); } else { LOGGER.info("ProcessEngine {} created", this.name); } ProcessEngines.registerProcessEngine(this); if (processEngineConfiguration.getProcessEngineLifecycleListener() != null) { processEngineConfiguration.getProcessEngineLifecycleListener().onProcessEngineBuilt(this); } processEngineConfiguration.getEventDispatcher().dispatchEvent(FlowableEventBuilder.createGlobalEvent(FlowableEngineEventType.ENGINE_CREATED)); if (this.asyncExecutor != null && this.asyncExecutor.isAutoActivate()) { this.asyncExecutor.start(); } if (this.asyncHistoryExecutor != null && this.asyncHistoryExecutor.isAutoActivate()) { this.asyncHistoryExecutor.start(); } } public void close() { ProcessEngines.unregister(this); if (this.asyncExecutor != null && this.asyncExecutor.isActive()) { this.asyncExecutor.shutdown(); } if (this.asyncHistoryExecutor != null && this.asyncHistoryExecutor.isActive()) { this.asyncHistoryExecutor.shutdown(); } Runnable closeRunnable = this.processEngineConfiguration.getProcessEngineCloseRunnable(); if (closeRunnable != null) { closeRunnable.run(); } if (this.processEngineConfiguration.getProcessEngineLifecycleListener() != null) { this.processEngineConfiguration.getProcessEngineLifecycleListener().onProcessEngineClosed(this); } this.processEngineConfiguration.getEventDispatcher().dispatchEvent(FlowableEventBuilder.createGlobalEvent(FlowableEngineEventType.ENGINE_CLOSED)); } public String getName() { return this.name; } public IdentityService getIdentityService() { return this.identityService; } public ManagementService getManagementService() { return this.managementService; } public TaskService getTaskService() { return this.taskService; } public HistoryService getHistoryService() { return this.historicDataService; } public RuntimeService getRuntimeService() { return this.runtimeService; } public RepositoryService getRepositoryService() { return this.repositoryService; } public FormService getFormService() { return this.formService; } public DynamicBpmnService getDynamicBpmnService() { return this.dynamicBpmnService; } public ProcessEngineConfigurationImpl getProcessEngineConfiguration() { return this.processEngineConfiguration; } }
例子
public class ModuleA { //示意方法 public void testA(){ System.out.println("调用ModuleA中的testA方法"); } } public class ModuleB { //示意方法 public void testB(){ System.out.println("调用ModuleB中的testB方法"); } } public class ModuleC { //示意方法 public void testC(){ System.out.println("调用ModuleC中的testC方法"); } }
public class Facade { //示意方法,满足客户端需要的功能 public void test(){ ModuleA a = new ModuleA(); a.testA(); ModuleB b = new ModuleB(); b.testB(); ModuleC c = new ModuleC(); c.testC(); } }
public class Facade { //示意方法,满足客户端需要的功能 public void test(){ ModuleA a = new ModuleA(); a.testA(); ModuleB b = new ModuleB(); b.testB(); ModuleC c = new ModuleC(); c.testC(); } }
public class Facade { //示意方法,满足客户端需要的功能 public void test(){ ModuleA a = new ModuleA(); a.testA(); ModuleB b = new ModuleB(); b.testB(); ModuleC c = new ModuleC(); c.testC(); } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!