开发者

name of this c++ implementation pattern

There is certain implementation pattern in C++, that I describe below, it 开发者_JAVA技巧is used in std::iostream library and other similar libraries.

Can anybody recall name of this pattern?

The pattern is described like this:

- There is central class IO used for output of data, or for conversion of data (e.g, std::ostream).

- for every application class for which output conversion is defined, "converters" are GLOBAL functions, not member functions of IO. The motivation for this pattern is

(1) designer of IO wants to have it "finished", not needing any changes when another application class with convertor is added, and

(2) because you want IO to be a small manageable class, not a class with 100 members and 1000s of lines. This pattern is common when decoupling is needed between IO class and multitude of "user" classes.

What is name of this pattern?


looks like it's the Herb Sutters' "Interface Principle"

at least I read it from one of his books

the interface must be minimal, all functions, which do not need private data (for compiling or runtime speed), should be in outer functions.


This is not a design pattern at all.

Design patterns are not tied to a programmng language. What you describe is done because the class std::ostream comes from a library. So you can not conveniently add "operator <<(MyClass &ob)" member functions.

The proper term instead of design pattern is "idiom". See e.g.: http://en.wikibooks.org/wiki/C++_Programming/Idioms or http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms (not sure if your case is listed, on a first glance I did not find it)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜