English 中文(简体)
C++ 设计模式图书馆
原标题:C++ Design Pattern library?

What is the most common C++ Design Pattern libraries?

I ve read about Loki library in Alexandrescu s book, but looks like it somewhat dead now. Is there something similar out there?

最佳回答

“Design patterns are bug reports against your programming language” -- Peter Norvig

为了回答为什么没有多少C++设计模式图书馆的问题,了解设计模式首先要解决的问题是有助益的。 典型的“GoF”书在序言中指出

Design patterns describe simple and elegant solutions to specific problems in object-oriented software design.

The 90s style of object-oriented programming relied heavily on using abstract classes as interfaces, with concrete implementation classes deriving from these interfaces. The GoF patterns describe creational, structural and behavioral relationships between objects of different class types. They key element was: encapsulate and parameterize whatever will frequently change. Many of the GoF patterns can also be reformulated using templates, but then the flexibility is constrained to compile-time rather than run-time.

面向目标的方案拟定非常容易增加一个接口的不同具体实施。 禁毒办很难为现有接口增加新的功能。 > 主要例子是:它基本上是一个依赖额外间接程度的工作,以便新的算法能够利用现有的数据结构。

This is the exact opposite of functional programming: with functional programming it is very easy to add new functions for existing data, but it is much harder to add new data types to which such functions apply. The difficulty in getting extensibility in both functions and types is called the expression problem.

OOP style polymorphism is heavily based on internal polymorphism: the dynamic function dispatch is based on the object s type. Modern C++ also uses external polymorphism where techniques such as type erasure allow run-time flexibility with a static interface. The new std::shared_ptr and boost::any or adobe::poly classes are prime example of these techniques.

A recent ACU由Tobias Darm介绍的情况表明,许多例子表明,旧的多环芳烃模式已转变为外部多变模式。 粗略的想法是用能够包含<条码>的功能论点取代抽象的班级:功能作为参数。 www.un.org/Depts/DGACM/index_french.htm 然后从外部控制多形态的灵活性。 在这种方式上,许多政府模式可以大大提高。

www.un.org/ga 通常的“政府财政”模式是专门设计的,目的是解决“共同行动”的不足。 但是,本组织已不能再成为占多数的C 0式。 采用一般方案(标准书库、博恩)和办公室方案,可以更经常地解决许多问题,使传统设计模式不会再成为解决之道。

问题回答

设计模式的原始定义是可检索的approach<>em> ,可追溯到一个可以而不是的反复出现问题,可方便地归入一个图书馆。 因此,当你can<>>/em>在图书馆内揭开一种模式时,我认为它不再是一种模式。 例如,由于标准C++图书馆有一个全面框架,现在主要在C++的主持人那里实施。

我从未试图使用Loki,但读过Alexandreescu的书,我并不相信,基于图书馆的做法确实有许多情况可以提供。

也许看起来美学,但最常见的是......标准图书馆本身!

它不是——严格地说是“家长图书馆”,而是处理共同模式实施的若干工具的夹。

请注意,你的问题无法回答,因为这是一种模式,仅仅是在各种问题中常用的概念定义。 图书馆不提供模式,它们(能够)利用模式(像其他人一样)提供具体问题的解决方案。

模式的抽象程度高于编码。

为了改进法典maintainability,re-usability,一些研究人员(如GoF, Booch)开始研究最佳做法。 他们注意到,有经验的开发商采用一些模式来处理具体的设计问题。

如你所知,experience创造了设计模式。 因此,使用设计模式正像一名专家一样编码。 也没有这方面的银弹。

It is true that some straightforward design patterns such as decorators find support from specific languages. But that s the limit. Domain specific frameworks also guide you to use their interfaces to complete the design pattern decided by the authors of those.

图书馆只能帮助你了解该图书馆使用的设计模式如何促进执行。 它甚至让你们选择改变设计。

I have tried to create a library that can be used to implement some of the GoF patterns using template classes: https://nwrkbiz.gitlab.io/cpp-design-patterns

这个图书馆背后的想法是使用模板,以便需要较少碎块的代码。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?