We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 27 days ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(7)
我希望你的意思是“哪些设计模式可以在STL中识别”。
STL 堆栈是一个容器适配器。适配器是一种设计模式。迭代器也是一种设计模式。 STL函数对象与命令模式相关。
模式:
这些模式的实现方式与面向对象设计中的实现方式非常不同。 Josuttis 写道“STL 概念与面向对象编程的原始思想相矛盾”。这就是导致您的问题出现混乱的原因。
I hope you mean, "which design patterns can be identified in the STL".
The STL stack is a container adapter. An adapter is a design pattern. The iterator is also a design pattern. The STL function objects are related to the command pattern.
Patterns:
The way these patterns are implemented is very different from the way they are implemented in an object oriented design. Josuttis wrote "the STL concept contradicts the original idea of object-oriented programming". This is what is causing the confusion around your question.
迭代器模式在STL中被大量使用。
The Iterator pattern is used pretty heavily in the STL.
STL 广泛使用模板。 GoF 调用此参数化类型。模板对于自定义设计模式解决方案或提出新的直观解决方案非常有用。 (有关更多详细信息,请参阅“设计模式:元素”中的“继承与参数化类型”部分可重用面向对象软件”)。熟悉 STL(和 boost)的好处是它们是了解模板的良好来源(和元编程)在 C++ 中,反过来又可以用于设计更好的设计。
STL makes extensive use of templates. GoF call this parameterized types. Templates are useful for customizing a design pattern solution or in coming up with a new, intuitive solution. (For more details, see the section "Inheritance versus Parameterized Types" in "Design Patterns: Elements of Reusable Object-Oriented Software"). The advantage of getting familiar with STL (and boost) is that they are a good source to learn about templates (and meta-programming) in C++, which in turn can be used in devising better designs.
我认为你的问题是设计模式没有在STL中实现。它们可以用 C++ 实现并使用 STL 中的容器和算法,但 STL 和设计模式没有任何其他方式相关。
我的建议是通过阅读Nicolai Josuttis 的优秀著作《C++ 标准库》来了解 STL:教程和参考或STL教程和参考指南。这将有助于了解 STL 可以为您做什么。然后利用您对 STL 的了解,深入研究在 C++ 中实现设计模式。
I think that your problem is that design patterns are not implemented in STL. They can be implemented in C++ and use containers and algorithms from STL but STL and Design Patterns are not related in any other way.
My advice would be to learn about STL by reading something like Nicolai Josuttis' excellent book The C++ Standard Library: A Tutorial and Reference or STL Tutorial and Reference Guide. This will help in learning what the STL can do for you. Then dig into implementing design patterns in C++ using your knowledge about the STL.
从C++11开始,我们有了三种智能指针,即shared_ptr、unique_ptr和weak_ptr,它们背后的模式是:代理模式。
From C++11, we got threes kinds of smart pointer, i.e, shared_ptr,unique_ptr and weak_ptr, the pattern behind them is :Proxy pattern.
std::vector::reference
和std::bitset::reference
也是代理模式的示例std::vector<bool>::reference
andstd::bitset::reference
are also examples of Proxy pattern在现代 STL 中,我从头到尾意识到:
What I am aware of from the top of my head in modern STL is: