桥接模式(Bridge Pattern)是一种结构型设计模式,它将抽象部分与其实现部分分离,使它们都可以独立变化。这种模式有时也被称作柄体(Handle and Body)模式或接口隔离模式。它的主要目的是将抽象层与实现层解耦,使得两者可以独立扩展而互不影响。核心是委托:将对自己的调用委托给其他对象。
classConcreteImplementationA : public Implementation { public: std::string OperationImplementation()constoverride{ return"ConcreteImplementationA: Here's the result on the platform A.\n"; } };
classConcreteImplementationB : public Implementation { public: std::string OperationImplementation()constoverride{ return"ConcreteImplementationB: Here's the result on the platform B.\n"; } };