Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To what extent modern C++ obviate the need for design patterns? [closed]

The Design Patterns book by GoF which came out in 1994 was written with C++ like languages in mind and many of the code examples were given in C++. Programmers of other languages felt that their languages did not need these 23 design patterns as those languages had features that made many of the patterns redundant.

From Wikipedia:

A primary criticism of Design Patterns is that its patterns are simply workarounds for missing features in C++, replacing elegant abstract features with lengthy concrete patterns, essentially becoming a "human compiler" or "generating by hand the expansions of some macro". Peter Norvig demonstrates that 16 out of the 23 patterns in Design Patterns are simplified or eliminated (via direct language support) in Lisp or Dylan.

C++ has undergone five revisions since the Design Patterns book came out (in 98, 03, 11, 14, 17). So the question is, to what extent does modern C++ simplify or eliminate the need for these 23 design patterns?

It would be good to list the Design Pattern along with the C++ language feature which eliminates or simplifies the need for that Pattern.

like image 966
P.W Avatar asked Aug 12 '18 12:08

P.W


2 Answers

I would say that Design Patterns are concepts which are modelled in a particular language using language features.

For example, as people stated in the comments, Command pattern can be modelled with std::function or any other callable.

But models do not make concepts unnecessary. Concepts are a very useful tool for thinking and designing, whereas models come in when implementing.

like image 90
Maxim Egorushkin Avatar answered Oct 19 '22 21:10

Maxim Egorushkin


You're right that a number of patterns aren't required now. However, some architectural patterns like adapter are "language-insensitive" and widely used in enterprise programming to decouple layers. Some patterns like visitor are more readable and better controlled that alternatives based on new language features. So I think the design patterns should be revised but not discarded.

like image 42
serge Avatar answered Oct 19 '22 21:10

serge