"Interface isolation" mode

The essence of the "interface isolation" mode is to use an additional layer of [indirect] stable interfaces to isolate interfaces that are originally closely related to each other. In fact, indirect methods can be reflected in many previous design patterns. For example, the principle of dependency inversion is to isolate the new method by adding a layer of indirect interface to achieve polymorphism. The unified isolation of interfaces here is just that he is very prominent.
1. Facade mode; mainly used for isolation between interior and exterior. It is to encapsulate a set of tightly coupled interfaces with a strong relationship and give them all to one interface. This is the facade, and the external access to some internal interfaces can only be accessed by accessing this facade interface.

唯一要注意的是这一组接口必须是很很强关系的并且紧耦合的

Insert picture description here

The agent model
adds a transparent indirect layer to agent some layers that are not known to the outside world, such as performance, security, etc.

Adapter; Just like the adapter in real life, one interface is converted into another interface for use, and the intermediate level is the adapter.
The core of its implementation is; there is an adapter class that inherits the new interface and combines the pointers of the old interface, so that when the methods of the inherited new interface are implemented, the methods of the old interface are combined to achieve the new interface.
At a specific time, these three steps can complete the new interface to call the old interface class.
oldInter *poldInter = new MyClass();//Old interface
newInter *pnewInter = new Adaper(poldInter);//The old interface is combined into the new interface
pnewInter->newPor();

#include "Adaper.h"

class newInter
{
public:
	newInter();
	~newInter();
	virtual void newPor();

private:

};
class  oldInter
{
public:
	oldInter();
	~oldInter();
	virtual void oldPor1();
	virtual void oldPor2();

private:

};
class MyClass : oldInter
{
public:
	MyClass();
	~MyClass();
	virtual void oldPor1(){};
	virtual void oldPor2(){};
private:

};

class Adaper : newInter//继承新接口
{
	oldInter * oldInter;//组合
public:
	Adaper(oldInter *oldInter){
		this->oldInter = oldInter;
	};
	~Adaper();
	virtual void newPor()//用旧接口的那一套实现新接口
	{
		oldInter->oldPor1();
		oldInter->oldPor2();
	}
};

int main()
{
	oldInter *poldInter = new MyClass();//旧接口
	newInter *pnewInter = new Adaper(poldInter);//旧接口组合成新接口
	pnewInter->newPor();
	return 0;
}

The intermediary mode; it is similar to the facade mode, except that the facade mode acts as an interface between the exterior and the interior, while the intermediary mode acts as an interface between the interior and the interior. When the internal internal interfaces are all very complicated, an intermediary can be created. To complete the management, but the intermediary needs to define a lot of protocol specifications to complete the corresponding management.

Insert picture description here

Guess you like

Origin blog.csdn.net/zw1996/article/details/99218949