开发者

Thin vs thick adapter (wrapper) example

开发者 https://www.devze.com 2023-02-10 02:20 出处:网络
I can\'t find any info on what is the difference between a thin and thick adapter. I would appreciate if someone can provide a description, followed with a simple example 开发者_运维问答(Please note t

I can't find any info on what is the difference between a thin and thick adapter. I would appreciate if someone can provide a description, followed with a simple example 开发者_运维问答(Please note that the example doesn't need to be in C++).

Thanks in advance.

EDIT: my vision of this is something like a class adapter pattern that requires minimum changes to conform to an expected interface.


This is quite simple.

For example, lets say you want to use the stat function in your code, but you want to be able to unit test your code, or even change which function to use at runtime. Then you would add a base class :

struct FunctionApiBase
{
 virtual ~FunctionApiBase{}

 virtual int stat(const char *path, struct stat *buf) = 0;
};

implement it :

struct RealFunctionApi : public FunctionApiBase
{
  virtual int stat(const char *path, struct stat *buf)
  {
    ::stat( path, buf );
  }
};

Then create object of type RealFunctionApi and call stat on it, instead of the real function.

If I understand the text in your link, thick adapter only has more complex code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号