STL中使用的设计模式(标准模板库)

时间:2023-02-14 13:19:19

I am learning STL and design patterns . i wanted to know is there any document or link that explains how design patterns are implemented in STL i did the google but not able to get much data

我正在学习STL和设计模式。我想知道是否有任何文档或链接可以解释在STL中如何实现设计模式,我在谷歌中实现了设计模式,但无法获得大量数据

5 个解决方案

#1


13  

I hope you mean, "which design patterns can be identified in the STL".

我希望您的意思是“在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.

STL堆栈是一个容器适配器。适配器是一种设计模式。迭代器也是一种设计模式。STL函数对象与命令模式相关。

Patterns:

模式:

  1. Adapter (container adapters)
    • stack
    • 堆栈
    • queues
    • 队列
    • priority queues
    • 优先级队列
  2. 适配器(容器适配器)堆栈队列优先级队列
  3. Iterator
  4. 迭代器
  5. Command + Adapter (function adapters)
  6. 命令+适配器(函数适配器)
  7. Iterator + Adapter (iterator adapters)
    • reverse iterators
    • 反向迭代器
    • insert iterators
    • 插入迭代器
    • stream iterators
    • 流迭代器
  8. 迭代器+适配器(迭代器适配器)反向迭代器插入迭代器流迭代器
  9. Template Method (STL algorithms using user-specified functions)
  10. 模板方法(使用用户指定函数的STL算法)
  11. Which creational pattern? (Allocators)
  12. 创建的模式?(分配器)

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.

这些模式的实现方式与它们在面向对象设计中的实现方式非常不同。Josuttis写道“STL概念与面向对象编程的原始思想相矛盾”。这就是你的问题引起困惑的原因。

#2


1  

The Iterator pattern is used pretty heavily in the STL.

迭代器模式在STL中被大量使用。

#3


1  

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广泛使用模板。GoF调用这个参数化类型。模板对于定制设计模式解决方案或提出新的、直观的解决方案非常有用。(有关详细信息,请参阅“设计模式:可重用面向对象软件的元素”中“继承与参数化类型”一节)。熟悉STL(和boost)的优势在于,它们是了解c++中模板(和元编程)的好方法,而c++可以用来设计更好的设计。

#4


1  

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.

我认为您的问题是设计模式没有在STL中实现。它们可以在c++中实现,并使用来自STL的容器和算法,但是STL和设计模式在其他方面没有任何关联。

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.

我的建议是通过阅读Nicolai Josuttis的优秀著作《c++标准图书馆:教程和参考》或STL教程和参考指南》来了解STL。这将有助于学习STL能为你做什么。然后,利用您对STL的了解,深入研究如何在c++中实现设计模式。

#5


0  

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.

从c++ 11,我们得到了三种智能指针i。e、shared_ptr、unique_ptr和weak_ptr背后的模式是:代理模式。

#1


13  

I hope you mean, "which design patterns can be identified in the STL".

我希望您的意思是“在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.

STL堆栈是一个容器适配器。适配器是一种设计模式。迭代器也是一种设计模式。STL函数对象与命令模式相关。

Patterns:

模式:

  1. Adapter (container adapters)
    • stack
    • 堆栈
    • queues
    • 队列
    • priority queues
    • 优先级队列
  2. 适配器(容器适配器)堆栈队列优先级队列
  3. Iterator
  4. 迭代器
  5. Command + Adapter (function adapters)
  6. 命令+适配器(函数适配器)
  7. Iterator + Adapter (iterator adapters)
    • reverse iterators
    • 反向迭代器
    • insert iterators
    • 插入迭代器
    • stream iterators
    • 流迭代器
  8. 迭代器+适配器(迭代器适配器)反向迭代器插入迭代器流迭代器
  9. Template Method (STL algorithms using user-specified functions)
  10. 模板方法(使用用户指定函数的STL算法)
  11. Which creational pattern? (Allocators)
  12. 创建的模式?(分配器)

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.

这些模式的实现方式与它们在面向对象设计中的实现方式非常不同。Josuttis写道“STL概念与面向对象编程的原始思想相矛盾”。这就是你的问题引起困惑的原因。

#2


1  

The Iterator pattern is used pretty heavily in the STL.

迭代器模式在STL中被大量使用。

#3


1  

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广泛使用模板。GoF调用这个参数化类型。模板对于定制设计模式解决方案或提出新的、直观的解决方案非常有用。(有关详细信息,请参阅“设计模式:可重用面向对象软件的元素”中“继承与参数化类型”一节)。熟悉STL(和boost)的优势在于,它们是了解c++中模板(和元编程)的好方法,而c++可以用来设计更好的设计。

#4


1  

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.

我认为您的问题是设计模式没有在STL中实现。它们可以在c++中实现,并使用来自STL的容器和算法,但是STL和设计模式在其他方面没有任何关联。

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.

我的建议是通过阅读Nicolai Josuttis的优秀著作《c++标准图书馆:教程和参考》或STL教程和参考指南》来了解STL。这将有助于学习STL能为你做什么。然后,利用您对STL的了解,深入研究如何在c++中实现设计模式。

#5


0  

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.

从c++ 11,我们得到了三种智能指针i。e、shared_ptr、unique_ptr和weak_ptr背后的模式是:代理模式。