13

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.

P.W
  • 26,289
  • 6
  • 39
  • 76
  • 3
    I would say *"command"* has free implementation with `std::function` and lambda. else I would say it is basically the same. – Jarod42 Aug 12 '18 at 13:02
  • If you mean Gemma-Helm-Johnson-Vlissides, then I find the book still relevant. However, I have not read the argument by Peter Norvig (no link?). – Kenny Ostrom Aug 12 '18 at 13:11
  • 1
    @KennyOstrom: Yes, that's the book. The link to Peter Norvig's argument is to be found in http://www.norvig.com/design-patterns/ – P.W Aug 12 '18 at 13:15
  • 1
    I would vote this for off-topic. Since it ts based on generic algorithms. also it may be a little opinion based. – apple apple Aug 12 '18 at 13:25
  • Maybe specific pattern (with implementation) is more on-topic? but it's working code... – apple apple Aug 12 '18 at 13:28
  • 1
    @appleapple: Instead of asking a question for each Pattern, I felt it would be better to address all of them in one. – P.W Aug 12 '18 at 13:32
  • @user846834 the implementation in that book, IIRC, are all out-of-date. and has better alternative. the idea, however, would be unable to answer without implementation and situation. – apple apple Aug 12 '18 at 13:33
  • Looks like the slides for what is probably a pretty interesting talk. Is this the right forum for an extended discussion with no right answer? Certainly some design patterns are easier in specific languages. Does that make them not patterns, or was the book done in a low level language to avoid dismissing things that are implemented for you in some higher level languages or libraries? – Kenny Ostrom Aug 12 '18 at 13:47
  • @KennyOstrom: My question is specific to C++ only. If GoF were to revise the book today taking into account all the revisions that C++ went through, would they eliminate any of the 23 patterns from the book because of the features included in the revisions? – P.W Aug 12 '18 at 13:54
  • @KennyOstrom: The book's authors, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides are collectively known as Gang of Four (GoF). – P.W Aug 12 '18 at 14:02
  • 2
    addressed fairly well in https://stackoverflow.com/questions/327955/does-functional-programming-replace-gof-design-patterns?rq=1 – Kenny Ostrom Aug 12 '18 at 14:04
  • I would also suggest that Iterator is pretty thoroughly implemented in c++. Oh, and I never remember GoF. Every time. Although I usually figure it out if someone actually says "gang of four" first. :) – Kenny Ostrom Aug 12 '18 at 14:05
  • 4
    Creational and structural patterns are trivial thanks to smart pointers and C++17 prvalue copy elision. A singleton is just a namespace. Structural and behavioral patterns are simplified by easier template meta programming. Behaviral pattern are simplified by the inclusion of functional programming inside c++ (lambda, ...). Behavioral and structural pattern would be damned simplified if we had the dot operator or when reflexion will be standardized. – Oliv Aug 12 '18 at 17:43

2 Answers2

1

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.

serge
  • 992
  • 5
  • 8
1

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.

Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271